Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / ada / sem_ch13.adb
bloba1e0dffe4d42b9038a4a3261475093b9d9a832e4
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-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Exp_Tss; use Exp_Tss;
32 with Exp_Util; use Exp_Util;
33 with Lib; use Lib;
34 with Nlists; use Nlists;
35 with Nmake; use Nmake;
36 with Opt; use Opt;
37 with Restrict; use Restrict;
38 with Rident; use Rident;
39 with Rtsfind; use Rtsfind;
40 with Sem; use Sem;
41 with Sem_Ch8; use Sem_Ch8;
42 with Sem_Eval; use Sem_Eval;
43 with Sem_Res; use Sem_Res;
44 with Sem_Type; use Sem_Type;
45 with Sem_Util; use Sem_Util;
46 with Snames; use Snames;
47 with Stand; use Stand;
48 with Sinfo; use Sinfo;
49 with Table;
50 with Targparm; use Targparm;
51 with Ttypes; use Ttypes;
52 with Tbuild; use Tbuild;
53 with Urealp; use Urealp;
55 with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
57 package body Sem_Ch13 is
59 SSU : constant Pos := System_Storage_Unit;
60 -- Convenient short hand for commonly used constant
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id);
67 -- This routine is called after setting the Esize of type entity Typ.
68 -- The purpose is to deal with the situation where an aligment has been
69 -- inherited from a derived type that is no longer appropriate for the
70 -- new Esize value. In this case, we reset the Alignment to unknown.
72 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
73 -- Given two entities for record components or discriminants, checks
74 -- if they hav overlapping component clauses and issues errors if so.
76 function Get_Alignment_Value (Expr : Node_Id) return Uint;
77 -- Given the expression for an alignment value, returns the corresponding
78 -- Uint value. If the value is inappropriate, then error messages are
79 -- posted as required, and a value of No_Uint is returned.
81 function Is_Operational_Item (N : Node_Id) return Boolean;
82 -- A specification for a stream attribute is allowed before the full
83 -- type is declared, as explained in AI-00137 and the corrigendum.
84 -- Attributes that do not specify a representation characteristic are
85 -- operational attributes.
87 function Address_Aliased_Entity (N : Node_Id) return Entity_Id;
88 -- If expression N is of the form E'Address, return E
90 procedure Mark_Aliased_Address_As_Volatile (N : Node_Id);
91 -- This is used for processing of an address representation clause. If
92 -- the expression N is of the form of K'Address, then the entity that
93 -- is associated with K is marked as volatile.
95 procedure New_Stream_Function
96 (N : Node_Id;
97 Ent : Entity_Id;
98 Subp : Entity_Id;
99 Nam : TSS_Name_Type);
100 -- Create a function renaming of a given stream attribute to the
101 -- designated subprogram and then in the tagged case, provide this as
102 -- a primitive operation, or in the non-tagged case make an appropriate
103 -- TSS entry. Used for Input. This is more properly an expansion activity
104 -- than just semantics, but the presence of user-defined stream functions
105 -- for limited types is a legality check, which is why this takes place
106 -- here rather than in exp_ch13, where it was previously. Nam indicates
107 -- the name of the TSS function to be generated.
109 -- To avoid elaboration anomalies with freeze nodes, for untagged types
110 -- we generate both a subprogram declaration and a subprogram renaming
111 -- declaration, so that the attribute specification is handled as a
112 -- renaming_as_body. For tagged types, the specification is one of the
113 -- primitive specs.
115 procedure New_Stream_Procedure
116 (N : Node_Id;
117 Ent : Entity_Id;
118 Subp : Entity_Id;
119 Nam : TSS_Name_Type;
120 Out_P : Boolean := False);
121 -- Create a procedure renaming of a given stream attribute to the
122 -- designated subprogram and then in the tagged case, provide this as
123 -- a primitive operation, or in the non-tagged case make an appropriate
124 -- TSS entry. Used for Read, Output, Write. Nam indicates the name of
125 -- the TSS procedure to be generated.
127 ----------------------------------------------
128 -- Table for Validate_Unchecked_Conversions --
129 ----------------------------------------------
131 -- The following table collects unchecked conversions for validation.
132 -- Entries are made by Validate_Unchecked_Conversion and then the
133 -- call to Validate_Unchecked_Conversions does the actual error
134 -- checking and posting of warnings. The reason for this delayed
135 -- processing is to take advantage of back-annotations of size and
136 -- alignment values peformed by the back end.
138 type UC_Entry is record
139 Enode : Node_Id; -- node used for posting warnings
140 Source : Entity_Id; -- source type for unchecked conversion
141 Target : Entity_Id; -- target type for unchecked conversion
142 end record;
144 package Unchecked_Conversions is new Table.Table (
145 Table_Component_Type => UC_Entry,
146 Table_Index_Type => Int,
147 Table_Low_Bound => 1,
148 Table_Initial => 50,
149 Table_Increment => 200,
150 Table_Name => "Unchecked_Conversions");
152 ----------------------------
153 -- Address_Aliased_Entity --
154 ----------------------------
156 function Address_Aliased_Entity (N : Node_Id) return Entity_Id is
157 begin
158 if Nkind (N) = N_Attribute_Reference
159 and then Attribute_Name (N) = Name_Address
160 then
161 declare
162 Nam : Node_Id := Prefix (N);
163 begin
164 while False
165 or else Nkind (Nam) = N_Selected_Component
166 or else Nkind (Nam) = N_Indexed_Component
167 loop
168 Nam := Prefix (Nam);
169 end loop;
171 if Is_Entity_Name (Nam) then
172 return Entity (Nam);
173 end if;
174 end;
175 end if;
177 return Empty;
178 end Address_Aliased_Entity;
180 --------------------------------------
181 -- Alignment_Check_For_Esize_Change --
182 --------------------------------------
184 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id) is
185 begin
186 -- If the alignment is known, and not set by a rep clause, and is
187 -- inconsistent with the size being set, then reset it to unknown,
188 -- we assume in this case that the size overrides the inherited
189 -- alignment, and that the alignment must be recomputed.
191 if Known_Alignment (Typ)
192 and then not Has_Alignment_Clause (Typ)
193 and then Esize (Typ) mod (Alignment (Typ) * SSU) /= 0
194 then
195 Init_Alignment (Typ);
196 end if;
197 end Alignment_Check_For_Esize_Change;
199 -----------------------
200 -- Analyze_At_Clause --
201 -----------------------
203 -- An at clause is replaced by the corresponding Address attribute
204 -- definition clause that is the preferred approach in Ada 95.
206 procedure Analyze_At_Clause (N : Node_Id) is
207 begin
208 Check_Restriction (No_Obsolescent_Features, N);
210 if Warn_On_Obsolescent_Feature then
211 Error_Msg_N
212 ("at clause is an obsolescent feature ('R'M 'J.7(2))?", N);
213 Error_Msg_N
214 ("\use address attribute definition clause instead?", N);
215 end if;
217 Rewrite (N,
218 Make_Attribute_Definition_Clause (Sloc (N),
219 Name => Identifier (N),
220 Chars => Name_Address,
221 Expression => Expression (N)));
222 Analyze_Attribute_Definition_Clause (N);
223 end Analyze_At_Clause;
225 -----------------------------------------
226 -- Analyze_Attribute_Definition_Clause --
227 -----------------------------------------
229 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
230 Loc : constant Source_Ptr := Sloc (N);
231 Nam : constant Node_Id := Name (N);
232 Attr : constant Name_Id := Chars (N);
233 Expr : constant Node_Id := Expression (N);
234 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
235 Ent : Entity_Id;
236 U_Ent : Entity_Id;
238 FOnly : Boolean := False;
239 -- Reset to True for subtype specific attribute (Alignment, Size)
240 -- and for stream attributes, i.e. those cases where in the call
241 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
242 -- rules are checked. Note that the case of stream attributes is not
243 -- clear from the RM, but see AI95-00137. Also, the RM seems to
244 -- disallow Storage_Size for derived task types, but that is also
245 -- clearly unintentional.
247 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
248 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
249 -- definition clauses.
251 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
252 Subp : Entity_Id := Empty;
253 I : Interp_Index;
254 It : Interp;
255 Pnam : Entity_Id;
257 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
259 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
260 -- Return true if the entity is a subprogram with an appropriate
261 -- profile for the attribute being defined.
263 ----------------------
264 -- Has_Good_Profile --
265 ----------------------
267 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
268 F : Entity_Id;
269 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
270 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
271 (False => E_Procedure, True => E_Function);
272 Typ : Entity_Id;
274 begin
275 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
276 return False;
277 end if;
279 F := First_Formal (Subp);
281 if No (F)
282 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
283 or else Designated_Type (Etype (F)) /=
284 Class_Wide_Type (RTE (RE_Root_Stream_Type))
285 then
286 return False;
287 end if;
289 if not Is_Function then
290 Next_Formal (F);
292 declare
293 Expected_Mode : constant array (Boolean) of Entity_Kind :=
294 (False => E_In_Parameter,
295 True => E_Out_Parameter);
296 begin
297 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
298 return False;
299 end if;
300 end;
302 Typ := Etype (F);
304 else
305 Typ := Etype (Subp);
306 end if;
308 return Base_Type (Typ) = Base_Type (Ent)
309 and then No (Next_Formal (F));
311 end Has_Good_Profile;
313 -- Start of processing for Analyze_Stream_TSS_Definition
315 begin
316 FOnly := True;
318 if not Is_Type (U_Ent) then
319 Error_Msg_N ("local name must be a subtype", Nam);
320 return;
321 end if;
323 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
325 if Present (Pnam) and then Has_Good_Profile (Pnam) then
326 Error_Msg_Sloc := Sloc (Pnam);
327 Error_Msg_Name_1 := Attr;
328 Error_Msg_N ("% attribute already defined #", Nam);
329 return;
330 end if;
332 Analyze (Expr);
334 if Is_Entity_Name (Expr) then
335 if not Is_Overloaded (Expr) then
336 if Has_Good_Profile (Entity (Expr)) then
337 Subp := Entity (Expr);
338 end if;
340 else
341 Get_First_Interp (Expr, I, It);
343 while Present (It.Nam) loop
344 if Has_Good_Profile (It.Nam) then
345 Subp := It.Nam;
346 exit;
347 end if;
349 Get_Next_Interp (I, It);
350 end loop;
351 end if;
352 end if;
354 if Present (Subp) then
355 if Is_Abstract (Subp) then
356 Error_Msg_N ("stream subprogram must not be abstract", Expr);
357 return;
358 end if;
360 Set_Entity (Expr, Subp);
361 Set_Etype (Expr, Etype (Subp));
363 if TSS_Nam = TSS_Stream_Input then
364 New_Stream_Function (N, U_Ent, Subp, TSS_Nam);
365 else
366 New_Stream_Procedure (N, U_Ent, Subp, TSS_Nam,
367 Out_P => Is_Read);
368 end if;
370 else
371 Error_Msg_Name_1 := Attr;
372 Error_Msg_N ("incorrect expression for% attribute", Expr);
373 end if;
374 end Analyze_Stream_TSS_Definition;
376 -- Start of processing for Analyze_Attribute_Definition_Clause
378 begin
379 Analyze (Nam);
380 Ent := Entity (Nam);
382 if Rep_Item_Too_Early (Ent, N) then
383 return;
384 end if;
386 -- Rep clause applies to full view of incomplete type or private type if
387 -- we have one (if not, this is a premature use of the type). However,
388 -- certain semantic checks need to be done on the specified entity (i.e.
389 -- the private view), so we save it in Ent.
391 if Is_Private_Type (Ent)
392 and then Is_Derived_Type (Ent)
393 and then not Is_Tagged_Type (Ent)
394 and then No (Full_View (Ent))
395 then
396 -- If this is a private type whose completion is a derivation from
397 -- another private type, there is no full view, and the attribute
398 -- belongs to the type itself, not its underlying parent.
400 U_Ent := Ent;
402 elsif Ekind (Ent) = E_Incomplete_Type then
404 -- The attribute applies to the full view, set the entity of the
405 -- attribute definition accordingly.
407 Ent := Underlying_Type (Ent);
408 U_Ent := Ent;
409 Set_Entity (Nam, Ent);
411 else
412 U_Ent := Underlying_Type (Ent);
413 end if;
415 -- Complete other routine error checks
417 if Etype (Nam) = Any_Type then
418 return;
420 elsif Scope (Ent) /= Current_Scope then
421 Error_Msg_N ("entity must be declared in this scope", Nam);
422 return;
424 elsif No (U_Ent) then
425 U_Ent := Ent;
427 elsif Is_Type (U_Ent)
428 and then not Is_First_Subtype (U_Ent)
429 and then Id /= Attribute_Object_Size
430 and then Id /= Attribute_Value_Size
431 and then not From_At_Mod (N)
432 then
433 Error_Msg_N ("cannot specify attribute for subtype", Nam);
434 return;
435 end if;
437 -- Switch on particular attribute
439 case Id is
441 -------------
442 -- Address --
443 -------------
445 -- Address attribute definition clause
447 when Attribute_Address => Address : begin
448 Analyze_And_Resolve (Expr, RTE (RE_Address));
450 if Present (Address_Clause (U_Ent)) then
451 Error_Msg_N ("address already given for &", Nam);
453 -- Case of address clause for subprogram
455 elsif Is_Subprogram (U_Ent) then
456 if Has_Homonym (U_Ent) then
457 Error_Msg_N
458 ("address clause cannot be given " &
459 "for overloaded subprogram",
460 Nam);
461 end if;
463 -- For subprograms, all address clauses are permitted,
464 -- and we mark the subprogram as having a deferred freeze
465 -- so that Gigi will not elaborate it too soon.
467 -- Above needs more comments, what is too soon about???
469 Set_Has_Delayed_Freeze (U_Ent);
471 -- Case of address clause for entry
473 elsif Ekind (U_Ent) = E_Entry then
474 if Nkind (Parent (N)) = N_Task_Body then
475 Error_Msg_N
476 ("entry address must be specified in task spec", Nam);
477 end if;
479 -- For entries, we require a constant address
481 Check_Constant_Address_Clause (Expr, U_Ent);
483 if Is_Task_Type (Scope (U_Ent))
484 and then Comes_From_Source (Scope (U_Ent))
485 then
486 Error_Msg_N
487 ("?entry address declared for entry in task type", N);
488 Error_Msg_N
489 ("\?only one task can be declared of this type", N);
490 end if;
492 Check_Restriction (No_Obsolescent_Features, N);
494 if Warn_On_Obsolescent_Feature then
495 Error_Msg_N
496 ("attaching interrupt to task entry is an " &
497 "obsolescent feature ('R'M 'J.7.1)?", N);
498 Error_Msg_N
499 ("\use interrupt procedure instead?", N);
500 end if;
502 -- Case of an address clause for a controlled object:
503 -- erroneous execution.
505 elsif Is_Controlled (Etype (U_Ent)) then
506 Error_Msg_NE
507 ("?controlled object& must not be overlaid", Nam, U_Ent);
508 Error_Msg_N
509 ("\?Program_Error will be raised at run time", Nam);
510 Insert_Action (Declaration_Node (U_Ent),
511 Make_Raise_Program_Error (Loc,
512 Reason => PE_Overlaid_Controlled_Object));
514 -- Case of address clause for a (non-controlled) object
516 elsif
517 Ekind (U_Ent) = E_Variable
518 or else
519 Ekind (U_Ent) = E_Constant
520 then
521 declare
522 Expr : constant Node_Id := Expression (N);
523 Aent : constant Entity_Id := Address_Aliased_Entity (Expr);
525 begin
526 -- Exported variables cannot have an address clause,
527 -- because this cancels the effect of the pragma Export
529 if Is_Exported (U_Ent) then
530 Error_Msg_N
531 ("cannot export object with address clause", Nam);
533 -- Overlaying controlled objects is erroneous
535 elsif Present (Aent)
536 and then Is_Controlled (Etype (Aent))
537 then
538 Error_Msg_N
539 ("?controlled object must not be overlaid", Expr);
540 Error_Msg_N
541 ("\?Program_Error will be raised at run time", Expr);
542 Insert_Action (Declaration_Node (U_Ent),
543 Make_Raise_Program_Error (Loc,
544 Reason => PE_Overlaid_Controlled_Object));
546 elsif Present (Aent)
547 and then Ekind (U_Ent) = E_Constant
548 and then Ekind (Aent) /= E_Constant
549 then
550 Error_Msg_N ("constant overlays a variable?", Expr);
552 elsif Present (Renamed_Object (U_Ent)) then
553 Error_Msg_N
554 ("address clause not allowed"
555 & " for a renaming declaration ('R'M 13.1(6))", Nam);
557 -- Imported variables can have an address clause, but then
558 -- the import is pretty meaningless except to suppress
559 -- initializations, so we do not need such variables to
560 -- be statically allocated (and in fact it causes trouble
561 -- if the address clause is a local value).
563 elsif Is_Imported (U_Ent) then
564 Set_Is_Statically_Allocated (U_Ent, False);
565 end if;
567 -- We mark a possible modification of a variable with an
568 -- address clause, since it is likely aliasing is occurring.
570 Note_Possible_Modification (Nam);
572 -- Here we are checking for explicit overlap of one
573 -- variable by another, and if we find this, then we
574 -- mark the overlapped variable as also being aliased.
576 -- First case is where we have an explicit
578 -- for J'Address use K'Address;
580 -- In this case, we mark K as volatile
582 Mark_Aliased_Address_As_Volatile (Expr);
584 -- Second case is where we have a constant whose
585 -- definition is of the form of an adress as in:
587 -- A : constant Address := K'Address;
588 -- ...
589 -- for B'Address use A;
591 -- In this case we also mark K as volatile
593 if Is_Entity_Name (Expr) then
594 declare
595 Ent : constant Entity_Id := Entity (Expr);
596 Decl : constant Node_Id := Declaration_Node (Ent);
598 begin
599 if Ekind (Ent) = E_Constant
600 and then Nkind (Decl) = N_Object_Declaration
601 and then Present (Expression (Decl))
602 then
603 Mark_Aliased_Address_As_Volatile
604 (Expression (Decl));
605 end if;
606 end;
607 end if;
609 -- Legality checks on the address clause for initialized
610 -- objects is deferred until the freeze point, because
611 -- a subsequent pragma might indicate that the object is
612 -- imported and thus not initialized.
614 Set_Has_Delayed_Freeze (U_Ent);
616 if Is_Exported (U_Ent) then
617 Error_Msg_N
618 ("& cannot be exported if an address clause is given",
619 Nam);
620 Error_Msg_N
621 ("\define and export a variable " &
622 "that holds its address instead",
623 Nam);
624 end if;
626 -- Entity has delayed freeze, so we will generate
627 -- an alignment check at the freeze point.
629 Set_Check_Address_Alignment
630 (N, not Range_Checks_Suppressed (U_Ent));
632 -- Kill the size check code, since we are not allocating
633 -- the variable, it is somewhere else.
635 Kill_Size_Check_Code (U_Ent);
636 end;
638 -- Not a valid entity for an address clause
640 else
641 Error_Msg_N ("address cannot be given for &", Nam);
642 end if;
643 end Address;
645 ---------------
646 -- Alignment --
647 ---------------
649 -- Alignment attribute definition clause
651 when Attribute_Alignment => Alignment_Block : declare
652 Align : constant Uint := Get_Alignment_Value (Expr);
654 begin
655 FOnly := True;
657 if not Is_Type (U_Ent)
658 and then Ekind (U_Ent) /= E_Variable
659 and then Ekind (U_Ent) /= E_Constant
660 then
661 Error_Msg_N ("alignment cannot be given for &", Nam);
663 elsif Has_Alignment_Clause (U_Ent) then
664 Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
665 Error_Msg_N ("alignment clause previously given#", N);
667 elsif Align /= No_Uint then
668 Set_Has_Alignment_Clause (U_Ent);
669 Set_Alignment (U_Ent, Align);
670 end if;
671 end Alignment_Block;
673 ---------------
674 -- Bit_Order --
675 ---------------
677 -- Bit_Order attribute definition clause
679 when Attribute_Bit_Order => Bit_Order : declare
680 begin
681 if not Is_Record_Type (U_Ent) then
682 Error_Msg_N
683 ("Bit_Order can only be defined for record type", Nam);
685 else
686 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
688 if Etype (Expr) = Any_Type then
689 return;
691 elsif not Is_Static_Expression (Expr) then
692 Flag_Non_Static_Expr
693 ("Bit_Order requires static expression!", Expr);
695 else
696 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
697 Set_Reverse_Bit_Order (U_Ent, True);
698 end if;
699 end if;
700 end if;
701 end Bit_Order;
703 --------------------
704 -- Component_Size --
705 --------------------
707 -- Component_Size attribute definition clause
709 when Attribute_Component_Size => Component_Size_Case : declare
710 Csize : constant Uint := Static_Integer (Expr);
711 Btype : Entity_Id;
712 Biased : Boolean;
713 New_Ctyp : Entity_Id;
714 Decl : Node_Id;
716 begin
717 if not Is_Array_Type (U_Ent) then
718 Error_Msg_N ("component size requires array type", Nam);
719 return;
720 end if;
722 Btype := Base_Type (U_Ent);
724 if Has_Component_Size_Clause (Btype) then
725 Error_Msg_N
726 ("component size clase for& previously given", Nam);
728 elsif Csize /= No_Uint then
729 Check_Size (Expr, Component_Type (Btype), Csize, Biased);
731 if Has_Aliased_Components (Btype)
732 and then Csize < 32
733 and then Csize /= 8
734 and then Csize /= 16
735 then
736 Error_Msg_N
737 ("component size incorrect for aliased components", N);
738 return;
739 end if;
741 -- For the biased case, build a declaration for a subtype
742 -- that will be used to represent the biased subtype that
743 -- reflects the biased representation of components. We need
744 -- this subtype to get proper conversions on referencing
745 -- elements of the array.
747 if Biased then
748 New_Ctyp :=
749 Make_Defining_Identifier (Loc,
750 Chars => New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
752 Decl :=
753 Make_Subtype_Declaration (Loc,
754 Defining_Identifier => New_Ctyp,
755 Subtype_Indication =>
756 New_Occurrence_Of (Component_Type (Btype), Loc));
758 Set_Parent (Decl, N);
759 Analyze (Decl, Suppress => All_Checks);
761 Set_Has_Delayed_Freeze (New_Ctyp, False);
762 Set_Esize (New_Ctyp, Csize);
763 Set_RM_Size (New_Ctyp, Csize);
764 Init_Alignment (New_Ctyp);
765 Set_Has_Biased_Representation (New_Ctyp, True);
766 Set_Is_Itype (New_Ctyp, True);
767 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
769 Set_Component_Type (Btype, New_Ctyp);
770 end if;
772 Set_Component_Size (Btype, Csize);
773 Set_Has_Component_Size_Clause (Btype, True);
774 Set_Has_Non_Standard_Rep (Btype, True);
775 end if;
776 end Component_Size_Case;
778 ------------------
779 -- External_Tag --
780 ------------------
782 when Attribute_External_Tag => External_Tag :
783 begin
784 if not Is_Tagged_Type (U_Ent) then
785 Error_Msg_N ("should be a tagged type", Nam);
786 end if;
788 Analyze_And_Resolve (Expr, Standard_String);
790 if not Is_Static_Expression (Expr) then
791 Flag_Non_Static_Expr
792 ("static string required for tag name!", Nam);
793 end if;
795 Set_Has_External_Tag_Rep_Clause (U_Ent);
796 end External_Tag;
798 -----------
799 -- Input --
800 -----------
802 when Attribute_Input =>
803 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
804 Set_Has_Specified_Stream_Input (Ent);
806 -------------------
807 -- Machine_Radix --
808 -------------------
810 -- Machine radix attribute definition clause
812 when Attribute_Machine_Radix => Machine_Radix : declare
813 Radix : constant Uint := Static_Integer (Expr);
815 begin
816 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
817 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
819 elsif Has_Machine_Radix_Clause (U_Ent) then
820 Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
821 Error_Msg_N ("machine radix clause previously given#", N);
823 elsif Radix /= No_Uint then
824 Set_Has_Machine_Radix_Clause (U_Ent);
825 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
827 if Radix = 2 then
828 null;
829 elsif Radix = 10 then
830 Set_Machine_Radix_10 (U_Ent);
831 else
832 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
833 end if;
834 end if;
835 end Machine_Radix;
837 -----------------
838 -- Object_Size --
839 -----------------
841 -- Object_Size attribute definition clause
843 when Attribute_Object_Size => Object_Size : declare
844 Size : constant Uint := Static_Integer (Expr);
845 Biased : Boolean;
847 begin
848 if not Is_Type (U_Ent) then
849 Error_Msg_N ("Object_Size cannot be given for &", Nam);
851 elsif Has_Object_Size_Clause (U_Ent) then
852 Error_Msg_N ("Object_Size already given for &", Nam);
854 else
855 Check_Size (Expr, U_Ent, Size, Biased);
857 if Size /= 8
858 and then
859 Size /= 16
860 and then
861 Size /= 32
862 and then
863 UI_Mod (Size, 64) /= 0
864 then
865 Error_Msg_N
866 ("Object_Size must be 8, 16, 32, or multiple of 64",
867 Expr);
868 end if;
870 Set_Esize (U_Ent, Size);
871 Set_Has_Object_Size_Clause (U_Ent);
872 Alignment_Check_For_Esize_Change (U_Ent);
873 end if;
874 end Object_Size;
876 ------------
877 -- Output --
878 ------------
880 when Attribute_Output =>
881 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
882 Set_Has_Specified_Stream_Output (Ent);
884 ----------
885 -- Read --
886 ----------
888 when Attribute_Read =>
889 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
890 Set_Has_Specified_Stream_Read (Ent);
892 ----------
893 -- Size --
894 ----------
896 -- Size attribute definition clause
898 when Attribute_Size => Size : declare
899 Size : constant Uint := Static_Integer (Expr);
900 Etyp : Entity_Id;
901 Biased : Boolean;
903 begin
904 FOnly := True;
906 if Has_Size_Clause (U_Ent) then
907 Error_Msg_N ("size already given for &", Nam);
909 elsif not Is_Type (U_Ent)
910 and then Ekind (U_Ent) /= E_Variable
911 and then Ekind (U_Ent) /= E_Constant
912 then
913 Error_Msg_N ("size cannot be given for &", Nam);
915 elsif Is_Array_Type (U_Ent)
916 and then not Is_Constrained (U_Ent)
917 then
918 Error_Msg_N
919 ("size cannot be given for unconstrained array", Nam);
921 elsif Size /= No_Uint then
922 if Is_Type (U_Ent) then
923 Etyp := U_Ent;
924 else
925 Etyp := Etype (U_Ent);
926 end if;
928 -- Check size, note that Gigi is in charge of checking
929 -- that the size of an array or record type is OK. Also
930 -- we do not check the size in the ordinary fixed-point
931 -- case, since it is too early to do so (there may be a
932 -- subsequent small clause that affects the size). We can
933 -- check the size if a small clause has already been given.
935 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
936 or else Has_Small_Clause (U_Ent)
937 then
938 Check_Size (Expr, Etyp, Size, Biased);
939 Set_Has_Biased_Representation (U_Ent, Biased);
940 end if;
942 -- For types set RM_Size and Esize if possible
944 if Is_Type (U_Ent) then
945 Set_RM_Size (U_Ent, Size);
947 -- For scalar types, increase Object_Size to power of 2,
948 -- but not less than a storage unit in any case (i.e.,
949 -- normally this means it will be byte addressable).
951 if Is_Scalar_Type (U_Ent) then
952 if Size <= System_Storage_Unit then
953 Init_Esize (U_Ent, System_Storage_Unit);
954 elsif Size <= 16 then
955 Init_Esize (U_Ent, 16);
956 elsif Size <= 32 then
957 Init_Esize (U_Ent, 32);
958 else
959 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
960 end if;
962 -- For all other types, object size = value size. The
963 -- backend will adjust as needed.
965 else
966 Set_Esize (U_Ent, Size);
967 end if;
969 Alignment_Check_For_Esize_Change (U_Ent);
971 -- For objects, set Esize only
973 else
974 if Is_Elementary_Type (Etyp) then
975 if Size /= System_Storage_Unit
976 and then
977 Size /= System_Storage_Unit * 2
978 and then
979 Size /= System_Storage_Unit * 4
980 and then
981 Size /= System_Storage_Unit * 8
982 then
983 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
984 Error_Msg_N
985 ("size for primitive object must be a power of 2"
986 & " and at least ^", N);
987 end if;
988 end if;
990 Set_Esize (U_Ent, Size);
991 end if;
993 Set_Has_Size_Clause (U_Ent);
994 end if;
995 end Size;
997 -----------
998 -- Small --
999 -----------
1001 -- Small attribute definition clause
1003 when Attribute_Small => Small : declare
1004 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
1005 Small : Ureal;
1007 begin
1008 Analyze_And_Resolve (Expr, Any_Real);
1010 if Etype (Expr) = Any_Type then
1011 return;
1013 elsif not Is_Static_Expression (Expr) then
1014 Flag_Non_Static_Expr
1015 ("small requires static expression!", Expr);
1016 return;
1018 else
1019 Small := Expr_Value_R (Expr);
1021 if Small <= Ureal_0 then
1022 Error_Msg_N ("small value must be greater than zero", Expr);
1023 return;
1024 end if;
1026 end if;
1028 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
1029 Error_Msg_N
1030 ("small requires an ordinary fixed point type", Nam);
1032 elsif Has_Small_Clause (U_Ent) then
1033 Error_Msg_N ("small already given for &", Nam);
1035 elsif Small > Delta_Value (U_Ent) then
1036 Error_Msg_N
1037 ("small value must not be greater then delta value", Nam);
1039 else
1040 Set_Small_Value (U_Ent, Small);
1041 Set_Small_Value (Implicit_Base, Small);
1042 Set_Has_Small_Clause (U_Ent);
1043 Set_Has_Small_Clause (Implicit_Base);
1044 Set_Has_Non_Standard_Rep (Implicit_Base);
1045 end if;
1046 end Small;
1048 ------------------
1049 -- Storage_Size --
1050 ------------------
1052 -- Storage_Size attribute definition clause
1054 when Attribute_Storage_Size => Storage_Size : declare
1055 Btype : constant Entity_Id := Base_Type (U_Ent);
1056 Sprag : Node_Id;
1058 begin
1059 if Is_Task_Type (U_Ent) then
1060 Check_Restriction (No_Obsolescent_Features, N);
1062 if Warn_On_Obsolescent_Feature then
1063 Error_Msg_N
1064 ("storage size clause for task is an " &
1065 "obsolescent feature ('R'M 'J.9)?", N);
1066 Error_Msg_N
1067 ("\use Storage_Size pragma instead?", N);
1068 end if;
1070 FOnly := True;
1071 end if;
1073 if not Is_Access_Type (U_Ent)
1074 and then Ekind (U_Ent) /= E_Task_Type
1075 then
1076 Error_Msg_N ("storage size cannot be given for &", Nam);
1078 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
1079 Error_Msg_N
1080 ("storage size cannot be given for a derived access type",
1081 Nam);
1083 elsif Has_Storage_Size_Clause (Btype) then
1084 Error_Msg_N ("storage size already given for &", Nam);
1086 else
1087 Analyze_And_Resolve (Expr, Any_Integer);
1089 if Is_Access_Type (U_Ent) then
1091 if Present (Associated_Storage_Pool (U_Ent)) then
1092 Error_Msg_N ("storage pool already given for &", Nam);
1093 return;
1094 end if;
1096 if Compile_Time_Known_Value (Expr)
1097 and then Expr_Value (Expr) = 0
1098 then
1099 Set_No_Pool_Assigned (Btype);
1100 end if;
1102 else -- Is_Task_Type (U_Ent)
1103 Sprag := Get_Rep_Pragma (Btype, Name_Storage_Size);
1105 if Present (Sprag) then
1106 Error_Msg_Sloc := Sloc (Sprag);
1107 Error_Msg_N
1108 ("Storage_Size already specified#", Nam);
1109 return;
1110 end if;
1111 end if;
1113 Set_Has_Storage_Size_Clause (Btype);
1114 end if;
1115 end Storage_Size;
1117 ------------------
1118 -- Storage_Pool --
1119 ------------------
1121 -- Storage_Pool attribute definition clause
1123 when Attribute_Storage_Pool => Storage_Pool : declare
1124 Pool : Entity_Id;
1125 T : Entity_Id;
1127 begin
1128 if Ekind (U_Ent) /= E_Access_Type
1129 and then Ekind (U_Ent) /= E_General_Access_Type
1130 then
1131 Error_Msg_N (
1132 "storage pool can only be given for access types", Nam);
1133 return;
1135 elsif Is_Derived_Type (U_Ent) then
1136 Error_Msg_N
1137 ("storage pool cannot be given for a derived access type",
1138 Nam);
1140 elsif Has_Storage_Size_Clause (U_Ent) then
1141 Error_Msg_N ("storage size already given for &", Nam);
1142 return;
1144 elsif Present (Associated_Storage_Pool (U_Ent)) then
1145 Error_Msg_N ("storage pool already given for &", Nam);
1146 return;
1147 end if;
1149 Analyze_And_Resolve
1150 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
1152 if Nkind (Expr) = N_Type_Conversion then
1153 T := Etype (Expression (Expr));
1154 else
1155 T := Etype (Expr);
1156 end if;
1158 -- The Stack_Bounded_Pool is used internally for implementing
1159 -- access types with a Storage_Size. Since it only work
1160 -- properly when used on one specific type, we need to check
1161 -- that it is not highjacked improperly:
1162 -- type T is access Integer;
1163 -- for T'Storage_Size use n;
1164 -- type Q is access Float;
1165 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
1167 if Base_Type (T) = RTE (RE_Stack_Bounded_Pool) then
1168 Error_Msg_N ("non-sharable internal Pool", Expr);
1169 return;
1170 end if;
1172 -- If the argument is a name that is not an entity name, then
1173 -- we construct a renaming operation to define an entity of
1174 -- type storage pool.
1176 if not Is_Entity_Name (Expr)
1177 and then Is_Object_Reference (Expr)
1178 then
1179 Pool :=
1180 Make_Defining_Identifier (Loc,
1181 Chars => New_Internal_Name ('P'));
1183 declare
1184 Rnode : constant Node_Id :=
1185 Make_Object_Renaming_Declaration (Loc,
1186 Defining_Identifier => Pool,
1187 Subtype_Mark =>
1188 New_Occurrence_Of (Etype (Expr), Loc),
1189 Name => Expr);
1191 begin
1192 Insert_Before (N, Rnode);
1193 Analyze (Rnode);
1194 Set_Associated_Storage_Pool (U_Ent, Pool);
1195 end;
1197 elsif Is_Entity_Name (Expr) then
1198 Pool := Entity (Expr);
1200 -- If pool is a renamed object, get original one. This can
1201 -- happen with an explicit renaming, and within instances.
1203 while Present (Renamed_Object (Pool))
1204 and then Is_Entity_Name (Renamed_Object (Pool))
1205 loop
1206 Pool := Entity (Renamed_Object (Pool));
1207 end loop;
1209 if Present (Renamed_Object (Pool))
1210 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
1211 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
1212 then
1213 Pool := Entity (Expression (Renamed_Object (Pool)));
1214 end if;
1216 Set_Associated_Storage_Pool (U_Ent, Pool);
1218 elsif Nkind (Expr) = N_Type_Conversion
1219 and then Is_Entity_Name (Expression (Expr))
1220 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
1221 then
1222 Pool := Entity (Expression (Expr));
1223 Set_Associated_Storage_Pool (U_Ent, Pool);
1225 else
1226 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
1227 return;
1228 end if;
1229 end Storage_Pool;
1231 -----------------
1232 -- Stream_Size --
1233 -----------------
1235 when Attribute_Stream_Size => Stream_Size : declare
1236 Size : constant Uint := Static_Integer (Expr);
1238 begin
1239 if Has_Stream_Size_Clause (U_Ent) then
1240 Error_Msg_N ("Stream_Size already given for &", Nam);
1242 elsif Is_Elementary_Type (U_Ent) then
1243 if Size /= System_Storage_Unit
1244 and then
1245 Size /= System_Storage_Unit * 2
1246 and then
1247 Size /= System_Storage_Unit * 4
1248 and then
1249 Size /= System_Storage_Unit * 8
1250 then
1251 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
1252 Error_Msg_N
1253 ("stream size for elementary type must be a"
1254 & " power of 2 and at least ^", N);
1256 elsif RM_Size (U_Ent) > Size then
1257 Error_Msg_Uint_1 := RM_Size (U_Ent);
1258 Error_Msg_N
1259 ("stream size for elementary type must be a"
1260 & " power of 2 and at least ^", N);
1261 end if;
1263 Set_Has_Stream_Size_Clause (U_Ent);
1265 else
1266 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
1267 end if;
1268 end Stream_Size;
1270 ----------------
1271 -- Value_Size --
1272 ----------------
1274 -- Value_Size attribute definition clause
1276 when Attribute_Value_Size => Value_Size : declare
1277 Size : constant Uint := Static_Integer (Expr);
1278 Biased : Boolean;
1280 begin
1281 if not Is_Type (U_Ent) then
1282 Error_Msg_N ("Value_Size cannot be given for &", Nam);
1284 elsif Present
1285 (Get_Attribute_Definition_Clause
1286 (U_Ent, Attribute_Value_Size))
1287 then
1288 Error_Msg_N ("Value_Size already given for &", Nam);
1290 else
1291 if Is_Elementary_Type (U_Ent) then
1292 Check_Size (Expr, U_Ent, Size, Biased);
1293 Set_Has_Biased_Representation (U_Ent, Biased);
1294 end if;
1296 Set_RM_Size (U_Ent, Size);
1297 end if;
1298 end Value_Size;
1300 -----------
1301 -- Write --
1302 -----------
1304 when Attribute_Write =>
1305 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
1306 Set_Has_Specified_Stream_Write (Ent);
1308 -- All other attributes cannot be set
1310 when others =>
1311 Error_Msg_N
1312 ("attribute& cannot be set with definition clause", N);
1313 end case;
1315 -- The test for the type being frozen must be performed after
1316 -- any expression the clause has been analyzed since the expression
1317 -- itself might cause freezing that makes the clause illegal.
1319 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
1320 return;
1321 end if;
1322 end Analyze_Attribute_Definition_Clause;
1324 ----------------------------
1325 -- Analyze_Code_Statement --
1326 ----------------------------
1328 procedure Analyze_Code_Statement (N : Node_Id) is
1329 HSS : constant Node_Id := Parent (N);
1330 SBody : constant Node_Id := Parent (HSS);
1331 Subp : constant Entity_Id := Current_Scope;
1332 Stmt : Node_Id;
1333 Decl : Node_Id;
1334 StmtO : Node_Id;
1335 DeclO : Node_Id;
1337 begin
1338 -- Analyze and check we get right type, note that this implements the
1339 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1340 -- is the only way that Asm_Insn could possibly be visible.
1342 Analyze_And_Resolve (Expression (N));
1344 if Etype (Expression (N)) = Any_Type then
1345 return;
1346 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
1347 Error_Msg_N ("incorrect type for code statement", N);
1348 return;
1349 end if;
1351 -- Make sure we appear in the handled statement sequence of a
1352 -- subprogram (RM 13.8(3)).
1354 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
1355 or else Nkind (SBody) /= N_Subprogram_Body
1356 then
1357 Error_Msg_N
1358 ("code statement can only appear in body of subprogram", N);
1359 return;
1360 end if;
1362 -- Do remaining checks (RM 13.8(3)) if not already done
1364 if not Is_Machine_Code_Subprogram (Subp) then
1365 Set_Is_Machine_Code_Subprogram (Subp);
1367 -- No exception handlers allowed
1369 if Present (Exception_Handlers (HSS)) then
1370 Error_Msg_N
1371 ("exception handlers not permitted in machine code subprogram",
1372 First (Exception_Handlers (HSS)));
1373 end if;
1375 -- No declarations other than use clauses and pragmas (we allow
1376 -- certain internally generated declarations as well).
1378 Decl := First (Declarations (SBody));
1379 while Present (Decl) loop
1380 DeclO := Original_Node (Decl);
1381 if Comes_From_Source (DeclO)
1382 and then Nkind (DeclO) /= N_Pragma
1383 and then Nkind (DeclO) /= N_Use_Package_Clause
1384 and then Nkind (DeclO) /= N_Use_Type_Clause
1385 and then Nkind (DeclO) /= N_Implicit_Label_Declaration
1386 then
1387 Error_Msg_N
1388 ("this declaration not allowed in machine code subprogram",
1389 DeclO);
1390 end if;
1392 Next (Decl);
1393 end loop;
1395 -- No statements other than code statements, pragmas, and labels.
1396 -- Again we allow certain internally generated statements.
1398 Stmt := First (Statements (HSS));
1399 while Present (Stmt) loop
1400 StmtO := Original_Node (Stmt);
1401 if Comes_From_Source (StmtO)
1402 and then Nkind (StmtO) /= N_Pragma
1403 and then Nkind (StmtO) /= N_Label
1404 and then Nkind (StmtO) /= N_Code_Statement
1405 then
1406 Error_Msg_N
1407 ("this statement is not allowed in machine code subprogram",
1408 StmtO);
1409 end if;
1411 Next (Stmt);
1412 end loop;
1413 end if;
1414 end Analyze_Code_Statement;
1416 -----------------------------------------------
1417 -- Analyze_Enumeration_Representation_Clause --
1418 -----------------------------------------------
1420 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
1421 Ident : constant Node_Id := Identifier (N);
1422 Aggr : constant Node_Id := Array_Aggregate (N);
1423 Enumtype : Entity_Id;
1424 Elit : Entity_Id;
1425 Expr : Node_Id;
1426 Assoc : Node_Id;
1427 Choice : Node_Id;
1428 Val : Uint;
1429 Err : Boolean := False;
1431 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
1432 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
1433 Min : Uint;
1434 Max : Uint;
1436 begin
1437 -- First some basic error checks
1439 Find_Type (Ident);
1440 Enumtype := Entity (Ident);
1442 if Enumtype = Any_Type
1443 or else Rep_Item_Too_Early (Enumtype, N)
1444 then
1445 return;
1446 else
1447 Enumtype := Underlying_Type (Enumtype);
1448 end if;
1450 if not Is_Enumeration_Type (Enumtype) then
1451 Error_Msg_NE
1452 ("enumeration type required, found}",
1453 Ident, First_Subtype (Enumtype));
1454 return;
1455 end if;
1457 -- Ignore rep clause on generic actual type. This will already have
1458 -- been flagged on the template as an error, and this is the safest
1459 -- way to ensure we don't get a junk cascaded message in the instance.
1461 if Is_Generic_Actual_Type (Enumtype) then
1462 return;
1464 -- Type must be in current scope
1466 elsif Scope (Enumtype) /= Current_Scope then
1467 Error_Msg_N ("type must be declared in this scope", Ident);
1468 return;
1470 -- Type must be a first subtype
1472 elsif not Is_First_Subtype (Enumtype) then
1473 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
1474 return;
1476 -- Ignore duplicate rep clause
1478 elsif Has_Enumeration_Rep_Clause (Enumtype) then
1479 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
1480 return;
1482 -- Don't allow rep clause for standard [wide_[wide_]]character
1484 elsif Root_Type (Enumtype) = Standard_Character
1485 or else Root_Type (Enumtype) = Standard_Wide_Character
1486 or else Root_Type (Enumtype) = Standard_Wide_Wide_Character
1487 then
1488 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
1489 return;
1491 -- Check that the expression is a proper aggregate (no parentheses)
1493 elsif Paren_Count (Aggr) /= 0 then
1494 Error_Msg
1495 ("extra parentheses surrounding aggregate not allowed",
1496 First_Sloc (Aggr));
1497 return;
1499 -- All tests passed, so set rep clause in place
1501 else
1502 Set_Has_Enumeration_Rep_Clause (Enumtype);
1503 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
1504 end if;
1506 -- Now we process the aggregate. Note that we don't use the normal
1507 -- aggregate code for this purpose, because we don't want any of the
1508 -- normal expansion activities, and a number of special semantic
1509 -- rules apply (including the component type being any integer type)
1511 Elit := First_Literal (Enumtype);
1513 -- First the positional entries if any
1515 if Present (Expressions (Aggr)) then
1516 Expr := First (Expressions (Aggr));
1517 while Present (Expr) loop
1518 if No (Elit) then
1519 Error_Msg_N ("too many entries in aggregate", Expr);
1520 return;
1521 end if;
1523 Val := Static_Integer (Expr);
1525 -- Err signals that we found some incorrect entries processing
1526 -- the list. The final checks for completeness and ordering are
1527 -- skipped in this case.
1529 if Val = No_Uint then
1530 Err := True;
1531 elsif Val < Lo or else Hi < Val then
1532 Error_Msg_N ("value outside permitted range", Expr);
1533 Err := True;
1534 end if;
1536 Set_Enumeration_Rep (Elit, Val);
1537 Set_Enumeration_Rep_Expr (Elit, Expr);
1538 Next (Expr);
1539 Next (Elit);
1540 end loop;
1541 end if;
1543 -- Now process the named entries if present
1545 if Present (Component_Associations (Aggr)) then
1546 Assoc := First (Component_Associations (Aggr));
1547 while Present (Assoc) loop
1548 Choice := First (Choices (Assoc));
1550 if Present (Next (Choice)) then
1551 Error_Msg_N
1552 ("multiple choice not allowed here", Next (Choice));
1553 Err := True;
1554 end if;
1556 if Nkind (Choice) = N_Others_Choice then
1557 Error_Msg_N ("others choice not allowed here", Choice);
1558 Err := True;
1560 elsif Nkind (Choice) = N_Range then
1561 -- ??? should allow zero/one element range here
1562 Error_Msg_N ("range not allowed here", Choice);
1563 Err := True;
1565 else
1566 Analyze_And_Resolve (Choice, Enumtype);
1568 if Is_Entity_Name (Choice)
1569 and then Is_Type (Entity (Choice))
1570 then
1571 Error_Msg_N ("subtype name not allowed here", Choice);
1572 Err := True;
1573 -- ??? should allow static subtype with zero/one entry
1575 elsif Etype (Choice) = Base_Type (Enumtype) then
1576 if not Is_Static_Expression (Choice) then
1577 Flag_Non_Static_Expr
1578 ("non-static expression used for choice!", Choice);
1579 Err := True;
1581 else
1582 Elit := Expr_Value_E (Choice);
1584 if Present (Enumeration_Rep_Expr (Elit)) then
1585 Error_Msg_Sloc := Sloc (Enumeration_Rep_Expr (Elit));
1586 Error_Msg_NE
1587 ("representation for& previously given#",
1588 Choice, Elit);
1589 Err := True;
1590 end if;
1592 Set_Enumeration_Rep_Expr (Elit, Choice);
1594 Expr := Expression (Assoc);
1595 Val := Static_Integer (Expr);
1597 if Val = No_Uint then
1598 Err := True;
1600 elsif Val < Lo or else Hi < Val then
1601 Error_Msg_N ("value outside permitted range", Expr);
1602 Err := True;
1603 end if;
1605 Set_Enumeration_Rep (Elit, Val);
1606 end if;
1607 end if;
1608 end if;
1610 Next (Assoc);
1611 end loop;
1612 end if;
1614 -- Aggregate is fully processed. Now we check that a full set of
1615 -- representations was given, and that they are in range and in order.
1616 -- These checks are only done if no other errors occurred.
1618 if not Err then
1619 Min := No_Uint;
1620 Max := No_Uint;
1622 Elit := First_Literal (Enumtype);
1623 while Present (Elit) loop
1624 if No (Enumeration_Rep_Expr (Elit)) then
1625 Error_Msg_NE ("missing representation for&!", N, Elit);
1627 else
1628 Val := Enumeration_Rep (Elit);
1630 if Min = No_Uint then
1631 Min := Val;
1632 end if;
1634 if Val /= No_Uint then
1635 if Max /= No_Uint and then Val <= Max then
1636 Error_Msg_NE
1637 ("enumeration value for& not ordered!",
1638 Enumeration_Rep_Expr (Elit), Elit);
1639 end if;
1641 Max := Val;
1642 end if;
1644 -- If there is at least one literal whose representation
1645 -- is not equal to the Pos value, then note that this
1646 -- enumeration type has a non-standard representation.
1648 if Val /= Enumeration_Pos (Elit) then
1649 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
1650 end if;
1651 end if;
1653 Next (Elit);
1654 end loop;
1656 -- Now set proper size information
1658 declare
1659 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
1661 begin
1662 if Has_Size_Clause (Enumtype) then
1663 if Esize (Enumtype) >= Minsize then
1664 null;
1666 else
1667 Minsize :=
1668 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
1670 if Esize (Enumtype) < Minsize then
1671 Error_Msg_N ("previously given size is too small", N);
1673 else
1674 Set_Has_Biased_Representation (Enumtype);
1675 end if;
1676 end if;
1678 else
1679 Set_RM_Size (Enumtype, Minsize);
1680 Set_Enum_Esize (Enumtype);
1681 end if;
1683 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
1684 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
1685 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
1686 end;
1687 end if;
1689 -- We repeat the too late test in case it froze itself!
1691 if Rep_Item_Too_Late (Enumtype, N) then
1692 null;
1693 end if;
1694 end Analyze_Enumeration_Representation_Clause;
1696 ----------------------------
1697 -- Analyze_Free_Statement --
1698 ----------------------------
1700 procedure Analyze_Free_Statement (N : Node_Id) is
1701 begin
1702 Analyze (Expression (N));
1703 end Analyze_Free_Statement;
1705 ------------------------------------------
1706 -- Analyze_Record_Representation_Clause --
1707 ------------------------------------------
1709 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
1710 Loc : constant Source_Ptr := Sloc (N);
1711 Ident : constant Node_Id := Identifier (N);
1712 Rectype : Entity_Id;
1713 Fent : Entity_Id;
1714 CC : Node_Id;
1715 Posit : Uint;
1716 Fbit : Uint;
1717 Lbit : Uint;
1718 Hbit : Uint := Uint_0;
1719 Comp : Entity_Id;
1720 Ocomp : Entity_Id;
1721 Biased : Boolean;
1723 Max_Bit_So_Far : Uint;
1724 -- Records the maximum bit position so far. If all field positions
1725 -- are monotonically increasing, then we can skip the circuit for
1726 -- checking for overlap, since no overlap is possible.
1728 Overlap_Check_Required : Boolean;
1729 -- Used to keep track of whether or not an overlap check is required
1731 Ccount : Natural := 0;
1732 -- Number of component clauses in record rep clause
1734 CR_Pragma : Node_Id := Empty;
1735 -- Points to N_Pragma node if Complete_Representation pragma present
1737 begin
1738 Find_Type (Ident);
1739 Rectype := Entity (Ident);
1741 if Rectype = Any_Type
1742 or else Rep_Item_Too_Early (Rectype, N)
1743 then
1744 return;
1745 else
1746 Rectype := Underlying_Type (Rectype);
1747 end if;
1749 -- First some basic error checks
1751 if not Is_Record_Type (Rectype) then
1752 Error_Msg_NE
1753 ("record type required, found}", Ident, First_Subtype (Rectype));
1754 return;
1756 elsif Is_Unchecked_Union (Rectype) then
1757 Error_Msg_N
1758 ("record rep clause not allowed for Unchecked_Union", N);
1760 elsif Scope (Rectype) /= Current_Scope then
1761 Error_Msg_N ("type must be declared in this scope", N);
1762 return;
1764 elsif not Is_First_Subtype (Rectype) then
1765 Error_Msg_N ("cannot give record rep clause for subtype", N);
1766 return;
1768 elsif Has_Record_Rep_Clause (Rectype) then
1769 Error_Msg_N ("duplicate record rep clause ignored", N);
1770 return;
1772 elsif Rep_Item_Too_Late (Rectype, N) then
1773 return;
1774 end if;
1776 if Present (Mod_Clause (N)) then
1777 declare
1778 Loc : constant Source_Ptr := Sloc (N);
1779 M : constant Node_Id := Mod_Clause (N);
1780 P : constant List_Id := Pragmas_Before (M);
1781 AtM_Nod : Node_Id;
1783 Mod_Val : Uint;
1784 pragma Warnings (Off, Mod_Val);
1786 begin
1787 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
1789 if Warn_On_Obsolescent_Feature then
1790 Error_Msg_N
1791 ("mod clause is an obsolescent feature ('R'M 'J.8)?", N);
1792 Error_Msg_N
1793 ("\use alignment attribute definition clause instead?", N);
1794 end if;
1796 if Present (P) then
1797 Analyze_List (P);
1798 end if;
1800 -- In ASIS_Mode mode, expansion is disabled, but we must
1801 -- convert the Mod clause into an alignment clause anyway, so
1802 -- that the back-end can compute and back-annotate properly the
1803 -- size and alignment of types that may include this record.
1805 if Operating_Mode = Check_Semantics
1806 and then ASIS_Mode
1807 then
1808 AtM_Nod :=
1809 Make_Attribute_Definition_Clause (Loc,
1810 Name => New_Reference_To (Base_Type (Rectype), Loc),
1811 Chars => Name_Alignment,
1812 Expression => Relocate_Node (Expression (M)));
1814 Set_From_At_Mod (AtM_Nod);
1815 Insert_After (N, AtM_Nod);
1816 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
1817 Set_Mod_Clause (N, Empty);
1819 else
1820 -- Get the alignment value to perform error checking
1822 Mod_Val := Get_Alignment_Value (Expression (M));
1824 end if;
1825 end;
1826 end if;
1828 -- Clear any existing component clauses for the type (this happens
1829 -- with derived types, where we are now overriding the original)
1831 Fent := First_Entity (Rectype);
1833 Comp := Fent;
1834 while Present (Comp) loop
1835 if Ekind (Comp) = E_Component
1836 or else Ekind (Comp) = E_Discriminant
1837 then
1838 Set_Component_Clause (Comp, Empty);
1839 end if;
1841 Next_Entity (Comp);
1842 end loop;
1844 -- All done if no component clauses
1846 CC := First (Component_Clauses (N));
1848 if No (CC) then
1849 return;
1850 end if;
1852 -- If a tag is present, then create a component clause that places
1853 -- it at the start of the record (otherwise gigi may place it after
1854 -- other fields that have rep clauses).
1856 if Nkind (Fent) = N_Defining_Identifier
1857 and then Chars (Fent) = Name_uTag
1858 then
1859 Set_Component_Bit_Offset (Fent, Uint_0);
1860 Set_Normalized_Position (Fent, Uint_0);
1861 Set_Normalized_First_Bit (Fent, Uint_0);
1862 Set_Normalized_Position_Max (Fent, Uint_0);
1863 Init_Esize (Fent, System_Address_Size);
1865 Set_Component_Clause (Fent,
1866 Make_Component_Clause (Loc,
1867 Component_Name =>
1868 Make_Identifier (Loc,
1869 Chars => Name_uTag),
1871 Position =>
1872 Make_Integer_Literal (Loc,
1873 Intval => Uint_0),
1875 First_Bit =>
1876 Make_Integer_Literal (Loc,
1877 Intval => Uint_0),
1879 Last_Bit =>
1880 Make_Integer_Literal (Loc,
1881 UI_From_Int (System_Address_Size))));
1883 Ccount := Ccount + 1;
1884 end if;
1886 -- A representation like this applies to the base type
1888 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
1889 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
1890 Set_Has_Specified_Layout (Base_Type (Rectype));
1892 Max_Bit_So_Far := Uint_Minus_1;
1893 Overlap_Check_Required := False;
1895 -- Process the component clauses
1897 while Present (CC) loop
1899 -- Pragma
1901 if Nkind (CC) = N_Pragma then
1902 Analyze (CC);
1904 -- The only pragma of interest is Complete_Representation
1906 if Chars (CC) = Name_Complete_Representation then
1907 CR_Pragma := CC;
1908 end if;
1910 -- Processing for real component clause
1912 else
1913 Ccount := Ccount + 1;
1914 Posit := Static_Integer (Position (CC));
1915 Fbit := Static_Integer (First_Bit (CC));
1916 Lbit := Static_Integer (Last_Bit (CC));
1918 if Posit /= No_Uint
1919 and then Fbit /= No_Uint
1920 and then Lbit /= No_Uint
1921 then
1922 if Posit < 0 then
1923 Error_Msg_N
1924 ("position cannot be negative", Position (CC));
1926 elsif Fbit < 0 then
1927 Error_Msg_N
1928 ("first bit cannot be negative", First_Bit (CC));
1930 -- Values look OK, so find the corresponding record component
1931 -- Even though the syntax allows an attribute reference for
1932 -- implementation-defined components, GNAT does not allow the
1933 -- tag to get an explicit position.
1935 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
1936 if Attribute_Name (Component_Name (CC)) = Name_Tag then
1937 Error_Msg_N ("position of tag cannot be specified", CC);
1938 else
1939 Error_Msg_N ("illegal component name", CC);
1940 end if;
1942 else
1943 Comp := First_Entity (Rectype);
1944 while Present (Comp) loop
1945 exit when Chars (Comp) = Chars (Component_Name (CC));
1946 Next_Entity (Comp);
1947 end loop;
1949 if No (Comp) then
1951 -- Maybe component of base type that is absent from
1952 -- statically constrained first subtype.
1954 Comp := First_Entity (Base_Type (Rectype));
1955 while Present (Comp) loop
1956 exit when Chars (Comp) = Chars (Component_Name (CC));
1957 Next_Entity (Comp);
1958 end loop;
1959 end if;
1961 if No (Comp) then
1962 Error_Msg_N
1963 ("component clause is for non-existent field", CC);
1965 elsif Present (Component_Clause (Comp)) then
1966 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
1967 Error_Msg_N
1968 ("component clause previously given#", CC);
1970 else
1971 -- Update Fbit and Lbit to the actual bit number
1973 Fbit := Fbit + UI_From_Int (SSU) * Posit;
1974 Lbit := Lbit + UI_From_Int (SSU) * Posit;
1976 if Fbit <= Max_Bit_So_Far then
1977 Overlap_Check_Required := True;
1978 else
1979 Max_Bit_So_Far := Lbit;
1980 end if;
1982 if Has_Size_Clause (Rectype)
1983 and then Esize (Rectype) <= Lbit
1984 then
1985 Error_Msg_N
1986 ("bit number out of range of specified size",
1987 Last_Bit (CC));
1988 else
1989 Set_Component_Clause (Comp, CC);
1990 Set_Component_Bit_Offset (Comp, Fbit);
1991 Set_Esize (Comp, 1 + (Lbit - Fbit));
1992 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
1993 Set_Normalized_Position (Comp, Fbit / SSU);
1995 Set_Normalized_Position_Max
1996 (Fent, Normalized_Position (Fent));
1998 if Is_Tagged_Type (Rectype)
1999 and then Fbit < System_Address_Size
2000 then
2001 Error_Msg_NE
2002 ("component overlaps tag field of&",
2003 CC, Rectype);
2004 end if;
2006 -- This information is also set in the corresponding
2007 -- component of the base type, found by accessing the
2008 -- Original_Record_Component link if it is present.
2010 Ocomp := Original_Record_Component (Comp);
2012 if Hbit < Lbit then
2013 Hbit := Lbit;
2014 end if;
2016 Check_Size
2017 (Component_Name (CC),
2018 Etype (Comp),
2019 Esize (Comp),
2020 Biased);
2022 Set_Has_Biased_Representation (Comp, Biased);
2024 if Present (Ocomp) then
2025 Set_Component_Clause (Ocomp, CC);
2026 Set_Component_Bit_Offset (Ocomp, Fbit);
2027 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
2028 Set_Normalized_Position (Ocomp, Fbit / SSU);
2029 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
2031 Set_Normalized_Position_Max
2032 (Ocomp, Normalized_Position (Ocomp));
2034 Set_Has_Biased_Representation
2035 (Ocomp, Has_Biased_Representation (Comp));
2036 end if;
2038 if Esize (Comp) < 0 then
2039 Error_Msg_N ("component size is negative", CC);
2040 end if;
2041 end if;
2042 end if;
2043 end if;
2044 end if;
2045 end if;
2047 Next (CC);
2048 end loop;
2050 -- Now that we have processed all the component clauses, check for
2051 -- overlap. We have to leave this till last, since the components
2052 -- can appear in any arbitrary order in the representation clause.
2054 -- We do not need this check if all specified ranges were monotonic,
2055 -- as recorded by Overlap_Check_Required being False at this stage.
2057 -- This first section checks if there are any overlapping entries
2058 -- at all. It does this by sorting all entries and then seeing if
2059 -- there are any overlaps. If there are none, then that is decisive,
2060 -- but if there are overlaps, they may still be OK (they may result
2061 -- from fields in different variants).
2063 if Overlap_Check_Required then
2064 Overlap_Check1 : declare
2066 OC_Fbit : array (0 .. Ccount) of Uint;
2067 -- First-bit values for component clauses, the value is the
2068 -- offset of the first bit of the field from start of record.
2069 -- The zero entry is for use in sorting.
2071 OC_Lbit : array (0 .. Ccount) of Uint;
2072 -- Last-bit values for component clauses, the value is the
2073 -- offset of the last bit of the field from start of record.
2074 -- The zero entry is for use in sorting.
2076 OC_Count : Natural := 0;
2077 -- Count of entries in OC_Fbit and OC_Lbit
2079 function OC_Lt (Op1, Op2 : Natural) return Boolean;
2080 -- Compare routine for Sort (See GNAT.Heap_Sort_A)
2082 procedure OC_Move (From : Natural; To : Natural);
2083 -- Move routine for Sort (see GNAT.Heap_Sort_A)
2085 function OC_Lt (Op1, Op2 : Natural) return Boolean is
2086 begin
2087 return OC_Fbit (Op1) < OC_Fbit (Op2);
2088 end OC_Lt;
2090 procedure OC_Move (From : Natural; To : Natural) is
2091 begin
2092 OC_Fbit (To) := OC_Fbit (From);
2093 OC_Lbit (To) := OC_Lbit (From);
2094 end OC_Move;
2096 begin
2097 CC := First (Component_Clauses (N));
2098 while Present (CC) loop
2099 if Nkind (CC) /= N_Pragma then
2100 Posit := Static_Integer (Position (CC));
2101 Fbit := Static_Integer (First_Bit (CC));
2102 Lbit := Static_Integer (Last_Bit (CC));
2104 if Posit /= No_Uint
2105 and then Fbit /= No_Uint
2106 and then Lbit /= No_Uint
2107 then
2108 OC_Count := OC_Count + 1;
2109 Posit := Posit * SSU;
2110 OC_Fbit (OC_Count) := Fbit + Posit;
2111 OC_Lbit (OC_Count) := Lbit + Posit;
2112 end if;
2113 end if;
2115 Next (CC);
2116 end loop;
2118 Sort
2119 (OC_Count,
2120 OC_Move'Unrestricted_Access,
2121 OC_Lt'Unrestricted_Access);
2123 Overlap_Check_Required := False;
2124 for J in 1 .. OC_Count - 1 loop
2125 if OC_Lbit (J) >= OC_Fbit (J + 1) then
2126 Overlap_Check_Required := True;
2127 exit;
2128 end if;
2129 end loop;
2130 end Overlap_Check1;
2131 end if;
2133 -- If Overlap_Check_Required is still True, then we have to do
2134 -- the full scale overlap check, since we have at least two fields
2135 -- that do overlap, and we need to know if that is OK since they
2136 -- are in the same variant, or whether we have a definite problem
2138 if Overlap_Check_Required then
2139 Overlap_Check2 : declare
2140 C1_Ent, C2_Ent : Entity_Id;
2141 -- Entities of components being checked for overlap
2143 Clist : Node_Id;
2144 -- Component_List node whose Component_Items are being checked
2146 Citem : Node_Id;
2147 -- Component declaration for component being checked
2149 begin
2150 C1_Ent := First_Entity (Base_Type (Rectype));
2152 -- Loop through all components in record. For each component check
2153 -- for overlap with any of the preceding elements on the component
2154 -- list containing the component, and also, if the component is in
2155 -- a variant, check against components outside the case structure.
2156 -- This latter test is repeated recursively up the variant tree.
2158 Main_Component_Loop : while Present (C1_Ent) loop
2159 if Ekind (C1_Ent) /= E_Component
2160 and then Ekind (C1_Ent) /= E_Discriminant
2161 then
2162 goto Continue_Main_Component_Loop;
2163 end if;
2165 -- Skip overlap check if entity has no declaration node. This
2166 -- happens with discriminants in constrained derived types.
2167 -- Probably we are missing some checks as a result, but that
2168 -- does not seem terribly serious ???
2170 if No (Declaration_Node (C1_Ent)) then
2171 goto Continue_Main_Component_Loop;
2172 end if;
2174 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
2176 -- Loop through component lists that need checking. Check the
2177 -- current component list and all lists in variants above us.
2179 Component_List_Loop : loop
2181 -- If derived type definition, go to full declaration
2182 -- If at outer level, check discriminants if there are any
2184 if Nkind (Clist) = N_Derived_Type_Definition then
2185 Clist := Parent (Clist);
2186 end if;
2188 -- Outer level of record definition, check discriminants
2190 if Nkind (Clist) = N_Full_Type_Declaration
2191 or else Nkind (Clist) = N_Private_Type_Declaration
2192 then
2193 if Has_Discriminants (Defining_Identifier (Clist)) then
2194 C2_Ent :=
2195 First_Discriminant (Defining_Identifier (Clist));
2197 while Present (C2_Ent) loop
2198 exit when C1_Ent = C2_Ent;
2199 Check_Component_Overlap (C1_Ent, C2_Ent);
2200 Next_Discriminant (C2_Ent);
2201 end loop;
2202 end if;
2204 -- Record extension case
2206 elsif Nkind (Clist) = N_Derived_Type_Definition then
2207 Clist := Empty;
2209 -- Otherwise check one component list
2211 else
2212 Citem := First (Component_Items (Clist));
2214 while Present (Citem) loop
2215 if Nkind (Citem) = N_Component_Declaration then
2216 C2_Ent := Defining_Identifier (Citem);
2217 exit when C1_Ent = C2_Ent;
2218 Check_Component_Overlap (C1_Ent, C2_Ent);
2219 end if;
2221 Next (Citem);
2222 end loop;
2223 end if;
2225 -- Check for variants above us (the parent of the Clist can
2226 -- be a variant, in which case its parent is a variant part,
2227 -- and the parent of the variant part is a component list
2228 -- whose components must all be checked against the current
2229 -- component for overlap.
2231 if Nkind (Parent (Clist)) = N_Variant then
2232 Clist := Parent (Parent (Parent (Clist)));
2234 -- Check for possible discriminant part in record, this is
2235 -- treated essentially as another level in the recursion.
2236 -- For this case we have the parent of the component list
2237 -- is the record definition, and its parent is the full
2238 -- type declaration which contains the discriminant
2239 -- specifications.
2241 elsif Nkind (Parent (Clist)) = N_Record_Definition then
2242 Clist := Parent (Parent ((Clist)));
2244 -- If neither of these two cases, we are at the top of
2245 -- the tree
2247 else
2248 exit Component_List_Loop;
2249 end if;
2250 end loop Component_List_Loop;
2252 <<Continue_Main_Component_Loop>>
2253 Next_Entity (C1_Ent);
2255 end loop Main_Component_Loop;
2256 end Overlap_Check2;
2257 end if;
2259 -- For records that have component clauses for all components, and
2260 -- whose size is less than or equal to 32, we need to know the size
2261 -- in the front end to activate possible packed array processing
2262 -- where the component type is a record.
2264 -- At this stage Hbit + 1 represents the first unused bit from all
2265 -- the component clauses processed, so if the component clauses are
2266 -- complete, then this is the length of the record.
2268 -- For records longer than System.Storage_Unit, and for those where
2269 -- not all components have component clauses, the back end determines
2270 -- the length (it may for example be appopriate to round up the size
2271 -- to some convenient boundary, based on alignment considerations etc).
2273 if Unknown_RM_Size (Rectype)
2274 and then Hbit + 1 <= 32
2275 then
2276 -- Nothing to do if at least one component with no component clause
2278 Comp := First_Entity (Rectype);
2279 while Present (Comp) loop
2280 if Ekind (Comp) = E_Component
2281 or else Ekind (Comp) = E_Discriminant
2282 then
2283 exit when No (Component_Clause (Comp));
2284 end if;
2286 Next_Entity (Comp);
2287 end loop;
2289 -- If we fall out of loop, all components have component clauses
2290 -- and so we can set the size to the maximum value.
2292 if No (Comp) then
2293 Set_RM_Size (Rectype, Hbit + 1);
2294 end if;
2295 end if;
2297 -- Check missing components if Complete_Representation pragma appeared
2299 if Present (CR_Pragma) then
2300 Comp := First_Entity (Rectype);
2301 while Present (Comp) loop
2302 if Ekind (Comp) = E_Component
2303 or else
2304 Ekind (Comp) = E_Discriminant
2305 then
2306 if No (Component_Clause (Comp)) then
2307 Error_Msg_NE
2308 ("missing component clause for &", CR_Pragma, Comp);
2309 end if;
2310 end if;
2312 Next_Entity (Comp);
2313 end loop;
2314 end if;
2315 end Analyze_Record_Representation_Clause;
2317 -----------------------------
2318 -- Check_Component_Overlap --
2319 -----------------------------
2321 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
2322 begin
2323 if Present (Component_Clause (C1_Ent))
2324 and then Present (Component_Clause (C2_Ent))
2325 then
2326 -- Exclude odd case where we have two tag fields in the same
2327 -- record, both at location zero. This seems a bit strange,
2328 -- but it seems to happen in some circumstances ???
2330 if Chars (C1_Ent) = Name_uTag
2331 and then Chars (C2_Ent) = Name_uTag
2332 then
2333 return;
2334 end if;
2336 -- Here we check if the two fields overlap
2338 declare
2339 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
2340 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
2341 E1 : constant Uint := S1 + Esize (C1_Ent);
2342 E2 : constant Uint := S2 + Esize (C2_Ent);
2344 begin
2345 if E2 <= S1 or else E1 <= S2 then
2346 null;
2347 else
2348 Error_Msg_Node_2 :=
2349 Component_Name (Component_Clause (C2_Ent));
2350 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
2351 Error_Msg_Node_1 :=
2352 Component_Name (Component_Clause (C1_Ent));
2353 Error_Msg_N
2354 ("component& overlaps & #",
2355 Component_Name (Component_Clause (C1_Ent)));
2356 end if;
2357 end;
2358 end if;
2359 end Check_Component_Overlap;
2361 -----------------------------------
2362 -- Check_Constant_Address_Clause --
2363 -----------------------------------
2365 procedure Check_Constant_Address_Clause
2366 (Expr : Node_Id;
2367 U_Ent : Entity_Id)
2369 procedure Check_At_Constant_Address (Nod : Node_Id);
2370 -- Checks that the given node N represents a name whose 'Address
2371 -- is constant (in the same sense as OK_Constant_Address_Clause,
2372 -- i.e. the address value is the same at the point of declaration
2373 -- of U_Ent and at the time of elaboration of the address clause.
2375 procedure Check_Expr_Constants (Nod : Node_Id);
2376 -- Checks that Nod meets the requirements for a constant address
2377 -- clause in the sense of the enclosing procedure.
2379 procedure Check_List_Constants (Lst : List_Id);
2380 -- Check that all elements of list Lst meet the requirements for a
2381 -- constant address clause in the sense of the enclosing procedure.
2383 -------------------------------
2384 -- Check_At_Constant_Address --
2385 -------------------------------
2387 procedure Check_At_Constant_Address (Nod : Node_Id) is
2388 begin
2389 if Is_Entity_Name (Nod) then
2390 if Present (Address_Clause (Entity ((Nod)))) then
2391 Error_Msg_NE
2392 ("invalid address clause for initialized object &!",
2393 Nod, U_Ent);
2394 Error_Msg_NE
2395 ("address for& cannot" &
2396 " depend on another address clause! ('R'M 13.1(22))!",
2397 Nod, U_Ent);
2399 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
2400 and then Sloc (U_Ent) < Sloc (Entity (Nod))
2401 then
2402 Error_Msg_NE
2403 ("invalid address clause for initialized object &!",
2404 Nod, U_Ent);
2405 Error_Msg_Name_1 := Chars (Entity (Nod));
2406 Error_Msg_Name_2 := Chars (U_Ent);
2407 Error_Msg_N
2408 ("\% must be defined before % ('R'M 13.1(22))!",
2409 Nod);
2410 end if;
2412 elsif Nkind (Nod) = N_Selected_Component then
2413 declare
2414 T : constant Entity_Id := Etype (Prefix (Nod));
2416 begin
2417 if (Is_Record_Type (T)
2418 and then Has_Discriminants (T))
2419 or else
2420 (Is_Access_Type (T)
2421 and then Is_Record_Type (Designated_Type (T))
2422 and then Has_Discriminants (Designated_Type (T)))
2423 then
2424 Error_Msg_NE
2425 ("invalid address clause for initialized object &!",
2426 Nod, U_Ent);
2427 Error_Msg_N
2428 ("\address cannot depend on component" &
2429 " of discriminated record ('R'M 13.1(22))!",
2430 Nod);
2431 else
2432 Check_At_Constant_Address (Prefix (Nod));
2433 end if;
2434 end;
2436 elsif Nkind (Nod) = N_Indexed_Component then
2437 Check_At_Constant_Address (Prefix (Nod));
2438 Check_List_Constants (Expressions (Nod));
2440 else
2441 Check_Expr_Constants (Nod);
2442 end if;
2443 end Check_At_Constant_Address;
2445 --------------------------
2446 -- Check_Expr_Constants --
2447 --------------------------
2449 procedure Check_Expr_Constants (Nod : Node_Id) is
2450 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
2451 Ent : Entity_Id := Empty;
2453 begin
2454 if Nkind (Nod) in N_Has_Etype
2455 and then Etype (Nod) = Any_Type
2456 then
2457 return;
2458 end if;
2460 case Nkind (Nod) is
2461 when N_Empty | N_Error =>
2462 return;
2464 when N_Identifier | N_Expanded_Name =>
2465 Ent := Entity (Nod);
2467 -- We need to look at the original node if it is different
2468 -- from the node, since we may have rewritten things and
2469 -- substituted an identifier representing the rewrite.
2471 if Original_Node (Nod) /= Nod then
2472 Check_Expr_Constants (Original_Node (Nod));
2474 -- If the node is an object declaration without initial
2475 -- value, some code has been expanded, and the expression
2476 -- is not constant, even if the constituents might be
2477 -- acceptable, as in A'Address + offset.
2479 if Ekind (Ent) = E_Variable
2480 and then Nkind (Declaration_Node (Ent))
2481 = N_Object_Declaration
2482 and then
2483 No (Expression (Declaration_Node (Ent)))
2484 then
2485 Error_Msg_NE
2486 ("invalid address clause for initialized object &!",
2487 Nod, U_Ent);
2489 -- If entity is constant, it may be the result of expanding
2490 -- a check. We must verify that its declaration appears
2491 -- before the object in question, else we also reject the
2492 -- address clause.
2494 elsif Ekind (Ent) = E_Constant
2495 and then In_Same_Source_Unit (Ent, U_Ent)
2496 and then Sloc (Ent) > Loc_U_Ent
2497 then
2498 Error_Msg_NE
2499 ("invalid address clause for initialized object &!",
2500 Nod, U_Ent);
2501 end if;
2503 return;
2504 end if;
2506 -- Otherwise look at the identifier and see if it is OK
2508 if Ekind (Ent) = E_Named_Integer
2509 or else
2510 Ekind (Ent) = E_Named_Real
2511 or else
2512 Is_Type (Ent)
2513 then
2514 return;
2516 elsif
2517 Ekind (Ent) = E_Constant
2518 or else
2519 Ekind (Ent) = E_In_Parameter
2520 then
2521 -- This is the case where we must have Ent defined
2522 -- before U_Ent. Clearly if they are in different
2523 -- units this requirement is met since the unit
2524 -- containing Ent is already processed.
2526 if not In_Same_Source_Unit (Ent, U_Ent) then
2527 return;
2529 -- Otherwise location of Ent must be before the
2530 -- location of U_Ent, that's what prior defined means.
2532 elsif Sloc (Ent) < Loc_U_Ent then
2533 return;
2535 else
2536 Error_Msg_NE
2537 ("invalid address clause for initialized object &!",
2538 Nod, U_Ent);
2539 Error_Msg_Name_1 := Chars (Ent);
2540 Error_Msg_Name_2 := Chars (U_Ent);
2541 Error_Msg_N
2542 ("\% must be defined before % ('R'M 13.1(22))!",
2543 Nod);
2544 end if;
2546 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
2547 Check_Expr_Constants (Original_Node (Nod));
2549 else
2550 Error_Msg_NE
2551 ("invalid address clause for initialized object &!",
2552 Nod, U_Ent);
2554 if Comes_From_Source (Ent) then
2555 Error_Msg_Name_1 := Chars (Ent);
2556 Error_Msg_N
2557 ("\reference to variable% not allowed"
2558 & " ('R'M 13.1(22))!", Nod);
2559 else
2560 Error_Msg_N
2561 ("non-static expression not allowed"
2562 & " ('R'M 13.1(22))!", Nod);
2563 end if;
2564 end if;
2566 when N_Integer_Literal =>
2568 -- If this is a rewritten unchecked conversion, in a system
2569 -- where Address is an integer type, always use the base type
2570 -- for a literal value. This is user-friendly and prevents
2571 -- order-of-elaboration issues with instances of unchecked
2572 -- conversion.
2574 if Nkind (Original_Node (Nod)) = N_Function_Call then
2575 Set_Etype (Nod, Base_Type (Etype (Nod)));
2576 end if;
2578 when N_Real_Literal |
2579 N_String_Literal |
2580 N_Character_Literal =>
2581 return;
2583 when N_Range =>
2584 Check_Expr_Constants (Low_Bound (Nod));
2585 Check_Expr_Constants (High_Bound (Nod));
2587 when N_Explicit_Dereference =>
2588 Check_Expr_Constants (Prefix (Nod));
2590 when N_Indexed_Component =>
2591 Check_Expr_Constants (Prefix (Nod));
2592 Check_List_Constants (Expressions (Nod));
2594 when N_Slice =>
2595 Check_Expr_Constants (Prefix (Nod));
2596 Check_Expr_Constants (Discrete_Range (Nod));
2598 when N_Selected_Component =>
2599 Check_Expr_Constants (Prefix (Nod));
2601 when N_Attribute_Reference =>
2602 if Attribute_Name (Nod) = Name_Address
2603 or else
2604 Attribute_Name (Nod) = Name_Access
2605 or else
2606 Attribute_Name (Nod) = Name_Unchecked_Access
2607 or else
2608 Attribute_Name (Nod) = Name_Unrestricted_Access
2609 then
2610 Check_At_Constant_Address (Prefix (Nod));
2612 else
2613 Check_Expr_Constants (Prefix (Nod));
2614 Check_List_Constants (Expressions (Nod));
2615 end if;
2617 when N_Aggregate =>
2618 Check_List_Constants (Component_Associations (Nod));
2619 Check_List_Constants (Expressions (Nod));
2621 when N_Component_Association =>
2622 Check_Expr_Constants (Expression (Nod));
2624 when N_Extension_Aggregate =>
2625 Check_Expr_Constants (Ancestor_Part (Nod));
2626 Check_List_Constants (Component_Associations (Nod));
2627 Check_List_Constants (Expressions (Nod));
2629 when N_Null =>
2630 return;
2632 when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In =>
2633 Check_Expr_Constants (Left_Opnd (Nod));
2634 Check_Expr_Constants (Right_Opnd (Nod));
2636 when N_Unary_Op =>
2637 Check_Expr_Constants (Right_Opnd (Nod));
2639 when N_Type_Conversion |
2640 N_Qualified_Expression |
2641 N_Allocator =>
2642 Check_Expr_Constants (Expression (Nod));
2644 when N_Unchecked_Type_Conversion =>
2645 Check_Expr_Constants (Expression (Nod));
2647 -- If this is a rewritten unchecked conversion, subtypes
2648 -- in this node are those created within the instance.
2649 -- To avoid order of elaboration issues, replace them
2650 -- with their base types. Note that address clauses can
2651 -- cause order of elaboration problems because they are
2652 -- elaborated by the back-end at the point of definition,
2653 -- and may mention entities declared in between (as long
2654 -- as everything is static). It is user-friendly to allow
2655 -- unchecked conversions in this context.
2657 if Nkind (Original_Node (Nod)) = N_Function_Call then
2658 Set_Etype (Expression (Nod),
2659 Base_Type (Etype (Expression (Nod))));
2660 Set_Etype (Nod, Base_Type (Etype (Nod)));
2661 end if;
2663 when N_Function_Call =>
2664 if not Is_Pure (Entity (Name (Nod))) then
2665 Error_Msg_NE
2666 ("invalid address clause for initialized object &!",
2667 Nod, U_Ent);
2669 Error_Msg_NE
2670 ("\function & is not pure ('R'M 13.1(22))!",
2671 Nod, Entity (Name (Nod)));
2673 else
2674 Check_List_Constants (Parameter_Associations (Nod));
2675 end if;
2677 when N_Parameter_Association =>
2678 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
2680 when others =>
2681 Error_Msg_NE
2682 ("invalid address clause for initialized object &!",
2683 Nod, U_Ent);
2684 Error_Msg_NE
2685 ("\must be constant defined before& ('R'M 13.1(22))!",
2686 Nod, U_Ent);
2687 end case;
2688 end Check_Expr_Constants;
2690 --------------------------
2691 -- Check_List_Constants --
2692 --------------------------
2694 procedure Check_List_Constants (Lst : List_Id) is
2695 Nod1 : Node_Id;
2697 begin
2698 if Present (Lst) then
2699 Nod1 := First (Lst);
2700 while Present (Nod1) loop
2701 Check_Expr_Constants (Nod1);
2702 Next (Nod1);
2703 end loop;
2704 end if;
2705 end Check_List_Constants;
2707 -- Start of processing for Check_Constant_Address_Clause
2709 begin
2710 Check_Expr_Constants (Expr);
2711 end Check_Constant_Address_Clause;
2713 ----------------
2714 -- Check_Size --
2715 ----------------
2717 procedure Check_Size
2718 (N : Node_Id;
2719 T : Entity_Id;
2720 Siz : Uint;
2721 Biased : out Boolean)
2723 UT : constant Entity_Id := Underlying_Type (T);
2724 M : Uint;
2726 begin
2727 Biased := False;
2729 -- Dismiss cases for generic types or types with previous errors
2731 if No (UT)
2732 or else UT = Any_Type
2733 or else Is_Generic_Type (UT)
2734 or else Is_Generic_Type (Root_Type (UT))
2735 then
2736 return;
2738 -- Check case of bit packed array
2740 elsif Is_Array_Type (UT)
2741 and then Known_Static_Component_Size (UT)
2742 and then Is_Bit_Packed_Array (UT)
2743 then
2744 declare
2745 Asiz : Uint;
2746 Indx : Node_Id;
2747 Ityp : Entity_Id;
2749 begin
2750 Asiz := Component_Size (UT);
2751 Indx := First_Index (UT);
2752 loop
2753 Ityp := Etype (Indx);
2755 -- If non-static bound, then we are not in the business of
2756 -- trying to check the length, and indeed an error will be
2757 -- issued elsewhere, since sizes of non-static array types
2758 -- cannot be set implicitly or explicitly.
2760 if not Is_Static_Subtype (Ityp) then
2761 return;
2762 end if;
2764 -- Otherwise accumulate next dimension
2766 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
2767 Expr_Value (Type_Low_Bound (Ityp)) +
2768 Uint_1);
2770 Next_Index (Indx);
2771 exit when No (Indx);
2772 end loop;
2774 if Asiz <= Siz then
2775 return;
2776 else
2777 Error_Msg_Uint_1 := Asiz;
2778 Error_Msg_NE
2779 ("size for& too small, minimum allowed is ^", N, T);
2780 Set_Esize (T, Asiz);
2781 Set_RM_Size (T, Asiz);
2782 end if;
2783 end;
2785 -- All other composite types are ignored
2787 elsif Is_Composite_Type (UT) then
2788 return;
2790 -- For fixed-point types, don't check minimum if type is not frozen,
2791 -- since we don't know all the characteristics of the type that can
2792 -- affect the size (e.g. a specified small) till freeze time.
2794 elsif Is_Fixed_Point_Type (UT)
2795 and then not Is_Frozen (UT)
2796 then
2797 null;
2799 -- Cases for which a minimum check is required
2801 else
2802 -- Ignore if specified size is correct for the type
2804 if Known_Esize (UT) and then Siz = Esize (UT) then
2805 return;
2806 end if;
2808 -- Otherwise get minimum size
2810 M := UI_From_Int (Minimum_Size (UT));
2812 if Siz < M then
2814 -- Size is less than minimum size, but one possibility remains
2815 -- that we can manage with the new size if we bias the type
2817 M := UI_From_Int (Minimum_Size (UT, Biased => True));
2819 if Siz < M then
2820 Error_Msg_Uint_1 := M;
2821 Error_Msg_NE
2822 ("size for& too small, minimum allowed is ^", N, T);
2823 Set_Esize (T, M);
2824 Set_RM_Size (T, M);
2825 else
2826 Biased := True;
2827 end if;
2828 end if;
2829 end if;
2830 end Check_Size;
2832 -------------------------
2833 -- Get_Alignment_Value --
2834 -------------------------
2836 function Get_Alignment_Value (Expr : Node_Id) return Uint is
2837 Align : constant Uint := Static_Integer (Expr);
2839 begin
2840 if Align = No_Uint then
2841 return No_Uint;
2843 elsif Align <= 0 then
2844 Error_Msg_N ("alignment value must be positive", Expr);
2845 return No_Uint;
2847 else
2848 for J in Int range 0 .. 64 loop
2849 declare
2850 M : constant Uint := Uint_2 ** J;
2852 begin
2853 exit when M = Align;
2855 if M > Align then
2856 Error_Msg_N
2857 ("alignment value must be power of 2", Expr);
2858 return No_Uint;
2859 end if;
2860 end;
2861 end loop;
2863 return Align;
2864 end if;
2865 end Get_Alignment_Value;
2867 ----------------
2868 -- Initialize --
2869 ----------------
2871 procedure Initialize is
2872 begin
2873 Unchecked_Conversions.Init;
2874 end Initialize;
2876 -------------------------
2877 -- Is_Operational_Item --
2878 -------------------------
2880 function Is_Operational_Item (N : Node_Id) return Boolean is
2881 begin
2882 if Nkind (N) /= N_Attribute_Definition_Clause then
2883 return False;
2884 else
2885 declare
2886 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
2888 begin
2889 return Id = Attribute_Input
2890 or else Id = Attribute_Output
2891 or else Id = Attribute_Read
2892 or else Id = Attribute_Write
2893 or else Id = Attribute_External_Tag;
2894 end;
2895 end if;
2896 end Is_Operational_Item;
2898 --------------------------------------
2899 -- Mark_Aliased_Address_As_Volatile --
2900 --------------------------------------
2902 procedure Mark_Aliased_Address_As_Volatile (N : Node_Id) is
2903 Ent : constant Entity_Id := Address_Aliased_Entity (N);
2905 begin
2906 if Present (Ent) then
2907 Set_Treat_As_Volatile (Ent);
2908 end if;
2909 end Mark_Aliased_Address_As_Volatile;
2911 ------------------
2912 -- Minimum_Size --
2913 ------------------
2915 function Minimum_Size
2916 (T : Entity_Id;
2917 Biased : Boolean := False) return Nat
2919 Lo : Uint := No_Uint;
2920 Hi : Uint := No_Uint;
2921 LoR : Ureal := No_Ureal;
2922 HiR : Ureal := No_Ureal;
2923 LoSet : Boolean := False;
2924 HiSet : Boolean := False;
2925 B : Uint;
2926 S : Nat;
2927 Ancest : Entity_Id;
2928 R_Typ : constant Entity_Id := Root_Type (T);
2930 begin
2931 -- If bad type, return 0
2933 if T = Any_Type then
2934 return 0;
2936 -- For generic types, just return zero. There cannot be any legitimate
2937 -- need to know such a size, but this routine may be called with a
2938 -- generic type as part of normal processing.
2940 elsif Is_Generic_Type (R_Typ)
2941 or else R_Typ = Any_Type
2942 then
2943 return 0;
2945 -- Access types. Normally an access type cannot have a size smaller
2946 -- than the size of System.Address. The exception is on VMS, where
2947 -- we have short and long addresses, and it is possible for an access
2948 -- type to have a short address size (and thus be less than the size
2949 -- of System.Address itself). We simply skip the check for VMS, and
2950 -- leave the back end to do the check.
2952 elsif Is_Access_Type (T) then
2953 if OpenVMS_On_Target then
2954 return 0;
2955 else
2956 return System_Address_Size;
2957 end if;
2959 -- Floating-point types
2961 elsif Is_Floating_Point_Type (T) then
2962 return UI_To_Int (Esize (R_Typ));
2964 -- Discrete types
2966 elsif Is_Discrete_Type (T) then
2968 -- The following loop is looking for the nearest compile time
2969 -- known bounds following the ancestor subtype chain. The idea
2970 -- is to find the most restrictive known bounds information.
2972 Ancest := T;
2973 loop
2974 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
2975 return 0;
2976 end if;
2978 if not LoSet then
2979 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
2980 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
2981 LoSet := True;
2982 exit when HiSet;
2983 end if;
2984 end if;
2986 if not HiSet then
2987 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
2988 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
2989 HiSet := True;
2990 exit when LoSet;
2991 end if;
2992 end if;
2994 Ancest := Ancestor_Subtype (Ancest);
2996 if No (Ancest) then
2997 Ancest := Base_Type (T);
2999 if Is_Generic_Type (Ancest) then
3000 return 0;
3001 end if;
3002 end if;
3003 end loop;
3005 -- Fixed-point types. We can't simply use Expr_Value to get the
3006 -- Corresponding_Integer_Value values of the bounds, since these
3007 -- do not get set till the type is frozen, and this routine can
3008 -- be called before the type is frozen. Similarly the test for
3009 -- bounds being static needs to include the case where we have
3010 -- unanalyzed real literals for the same reason.
3012 elsif Is_Fixed_Point_Type (T) then
3014 -- The following loop is looking for the nearest compile time
3015 -- known bounds following the ancestor subtype chain. The idea
3016 -- is to find the most restrictive known bounds information.
3018 Ancest := T;
3019 loop
3020 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
3021 return 0;
3022 end if;
3024 if not LoSet then
3025 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
3026 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
3027 then
3028 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
3029 LoSet := True;
3030 exit when HiSet;
3031 end if;
3032 end if;
3034 if not HiSet then
3035 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
3036 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
3037 then
3038 HiR := Expr_Value_R (Type_High_Bound (Ancest));
3039 HiSet := True;
3040 exit when LoSet;
3041 end if;
3042 end if;
3044 Ancest := Ancestor_Subtype (Ancest);
3046 if No (Ancest) then
3047 Ancest := Base_Type (T);
3049 if Is_Generic_Type (Ancest) then
3050 return 0;
3051 end if;
3052 end if;
3053 end loop;
3055 Lo := UR_To_Uint (LoR / Small_Value (T));
3056 Hi := UR_To_Uint (HiR / Small_Value (T));
3058 -- No other types allowed
3060 else
3061 raise Program_Error;
3062 end if;
3064 -- Fall through with Hi and Lo set. Deal with biased case
3066 if (Biased and then not Is_Fixed_Point_Type (T))
3067 or else Has_Biased_Representation (T)
3068 then
3069 Hi := Hi - Lo;
3070 Lo := Uint_0;
3071 end if;
3073 -- Signed case. Note that we consider types like range 1 .. -1 to be
3074 -- signed for the purpose of computing the size, since the bounds
3075 -- have to be accomodated in the base type.
3077 if Lo < 0 or else Hi < 0 then
3078 S := 1;
3079 B := Uint_1;
3081 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3082 -- Note that we accommodate the case where the bounds cross. This
3083 -- can happen either because of the way the bounds are declared
3084 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3086 while Lo < -B
3087 or else Hi < -B
3088 or else Lo >= B
3089 or else Hi >= B
3090 loop
3091 B := Uint_2 ** S;
3092 S := S + 1;
3093 end loop;
3095 -- Unsigned case
3097 else
3098 -- If both bounds are positive, make sure that both are represen-
3099 -- table in the case where the bounds are crossed. This can happen
3100 -- either because of the way the bounds are declared, or because of
3101 -- the algorithm in Freeze_Fixed_Point_Type.
3103 if Lo > Hi then
3104 Hi := Lo;
3105 end if;
3107 -- S = size, (can accommodate 0 .. (2**size - 1))
3109 S := 0;
3110 while Hi >= Uint_2 ** S loop
3111 S := S + 1;
3112 end loop;
3113 end if;
3115 return S;
3116 end Minimum_Size;
3118 -------------------------
3119 -- New_Stream_Function --
3120 -------------------------
3122 procedure New_Stream_Function
3123 (N : Node_Id;
3124 Ent : Entity_Id;
3125 Subp : Entity_Id;
3126 Nam : TSS_Name_Type)
3128 Loc : constant Source_Ptr := Sloc (N);
3129 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
3130 Subp_Id : Entity_Id;
3131 Subp_Decl : Node_Id;
3132 F : Entity_Id;
3133 Etyp : Entity_Id;
3135 function Build_Spec return Node_Id;
3136 -- Used for declaration and renaming declaration, so that this is
3137 -- treated as a renaming_as_body.
3139 ----------------
3140 -- Build_Spec --
3141 ----------------
3143 function Build_Spec return Node_Id is
3144 begin
3145 Subp_Id := Make_Defining_Identifier (Loc, Sname);
3147 return
3148 Make_Function_Specification (Loc,
3149 Defining_Unit_Name => Subp_Id,
3150 Parameter_Specifications =>
3151 New_List (
3152 Make_Parameter_Specification (Loc,
3153 Defining_Identifier =>
3154 Make_Defining_Identifier (Loc, Name_S),
3155 Parameter_Type =>
3156 Make_Access_Definition (Loc,
3157 Subtype_Mark =>
3158 New_Reference_To (
3159 Designated_Type (Etype (F)), Loc)))),
3161 Result_Definition =>
3162 New_Reference_To (Etyp, Loc));
3163 end Build_Spec;
3165 -- Start of processing for New_Stream_Function
3167 begin
3168 F := First_Formal (Subp);
3169 Etyp := Etype (Subp);
3171 if not Is_Tagged_Type (Ent) then
3172 Subp_Decl :=
3173 Make_Subprogram_Declaration (Loc,
3174 Specification => Build_Spec);
3175 Insert_Action (N, Subp_Decl);
3176 end if;
3178 Subp_Decl :=
3179 Make_Subprogram_Renaming_Declaration (Loc,
3180 Specification => Build_Spec,
3181 Name => New_Reference_To (Subp, Loc));
3183 if Is_Tagged_Type (Ent) then
3184 Set_TSS (Base_Type (Ent), Subp_Id);
3185 else
3186 Insert_Action (N, Subp_Decl);
3187 Copy_TSS (Subp_Id, Base_Type (Ent));
3188 end if;
3189 end New_Stream_Function;
3191 --------------------------
3192 -- New_Stream_Procedure --
3193 --------------------------
3195 procedure New_Stream_Procedure
3196 (N : Node_Id;
3197 Ent : Entity_Id;
3198 Subp : Entity_Id;
3199 Nam : TSS_Name_Type;
3200 Out_P : Boolean := False)
3202 Loc : constant Source_Ptr := Sloc (N);
3203 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
3204 Subp_Id : Entity_Id;
3205 Subp_Decl : Node_Id;
3206 F : Entity_Id;
3207 Etyp : Entity_Id;
3209 function Build_Spec return Node_Id;
3210 -- Used for declaration and renaming declaration, so that this is
3211 -- treated as a renaming_as_body.
3213 ----------------
3214 -- Build_Spec --
3215 ----------------
3217 function Build_Spec return Node_Id is
3218 begin
3219 Subp_Id := Make_Defining_Identifier (Loc, Sname);
3221 return
3222 Make_Procedure_Specification (Loc,
3223 Defining_Unit_Name => Subp_Id,
3224 Parameter_Specifications =>
3225 New_List (
3226 Make_Parameter_Specification (Loc,
3227 Defining_Identifier =>
3228 Make_Defining_Identifier (Loc, Name_S),
3229 Parameter_Type =>
3230 Make_Access_Definition (Loc,
3231 Subtype_Mark =>
3232 New_Reference_To (
3233 Designated_Type (Etype (F)), Loc))),
3235 Make_Parameter_Specification (Loc,
3236 Defining_Identifier =>
3237 Make_Defining_Identifier (Loc, Name_V),
3238 Out_Present => Out_P,
3239 Parameter_Type =>
3240 New_Reference_To (Etyp, Loc))));
3241 end Build_Spec;
3243 -- Start of processing for New_Stream_Procedure
3245 begin
3246 F := First_Formal (Subp);
3247 Etyp := Etype (Next_Formal (F));
3249 if not Is_Tagged_Type (Ent) then
3250 Subp_Decl :=
3251 Make_Subprogram_Declaration (Loc,
3252 Specification => Build_Spec);
3253 Insert_Action (N, Subp_Decl);
3254 end if;
3256 Subp_Decl :=
3257 Make_Subprogram_Renaming_Declaration (Loc,
3258 Specification => Build_Spec,
3259 Name => New_Reference_To (Subp, Loc));
3261 if Is_Tagged_Type (Ent) then
3262 Set_TSS (Base_Type (Ent), Subp_Id);
3263 else
3264 Insert_Action (N, Subp_Decl);
3265 Copy_TSS (Subp_Id, Base_Type (Ent));
3266 end if;
3267 end New_Stream_Procedure;
3269 ------------------------
3270 -- Rep_Item_Too_Early --
3271 ------------------------
3273 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
3274 begin
3275 -- Cannot apply rep items that are not operational items
3276 -- to generic types
3278 if Is_Operational_Item (N) then
3279 return False;
3281 elsif Is_Type (T)
3282 and then Is_Generic_Type (Root_Type (T))
3283 then
3284 Error_Msg_N
3285 ("representation item not allowed for generic type", N);
3286 return True;
3287 end if;
3289 -- Otherwise check for incompleted type
3291 if Is_Incomplete_Or_Private_Type (T)
3292 and then No (Underlying_Type (T))
3293 then
3294 Error_Msg_N
3295 ("representation item must be after full type declaration", N);
3296 return True;
3298 -- If the type has incompleted components, a representation clause is
3299 -- illegal but stream attributes and Convention pragmas are correct.
3301 elsif Has_Private_Component (T) then
3302 if Nkind (N) = N_Pragma then
3303 return False;
3304 else
3305 Error_Msg_N
3306 ("representation item must appear after type is fully defined",
3308 return True;
3309 end if;
3310 else
3311 return False;
3312 end if;
3313 end Rep_Item_Too_Early;
3315 -----------------------
3316 -- Rep_Item_Too_Late --
3317 -----------------------
3319 function Rep_Item_Too_Late
3320 (T : Entity_Id;
3321 N : Node_Id;
3322 FOnly : Boolean := False) return Boolean
3324 S : Entity_Id;
3325 Parent_Type : Entity_Id;
3327 procedure Too_Late;
3328 -- Output the too late message. Note that this is not considered a
3329 -- serious error, since the effect is simply that we ignore the
3330 -- representation clause in this case.
3332 --------------
3333 -- Too_Late --
3334 --------------
3336 procedure Too_Late is
3337 begin
3338 Error_Msg_N ("|representation item appears too late!", N);
3339 end Too_Late;
3341 -- Start of processing for Rep_Item_Too_Late
3343 begin
3344 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3345 -- types, which may be frozen if they appear in a representation clause
3346 -- for a local type.
3348 if Is_Frozen (T)
3349 and then not From_With_Type (T)
3350 then
3351 Too_Late;
3352 S := First_Subtype (T);
3354 if Present (Freeze_Node (S)) then
3355 Error_Msg_NE
3356 ("?no more representation items for }!", Freeze_Node (S), S);
3357 end if;
3359 return True;
3361 -- Check for case of non-tagged derived type whose parent either has
3362 -- primitive operations, or is a by reference type (RM 13.1(10)).
3364 elsif Is_Type (T)
3365 and then not FOnly
3366 and then Is_Derived_Type (T)
3367 and then not Is_Tagged_Type (T)
3368 then
3369 Parent_Type := Etype (Base_Type (T));
3371 if Has_Primitive_Operations (Parent_Type) then
3372 Too_Late;
3373 Error_Msg_NE
3374 ("primitive operations already defined for&!", N, Parent_Type);
3375 return True;
3377 elsif Is_By_Reference_Type (Parent_Type) then
3378 Too_Late;
3379 Error_Msg_NE
3380 ("parent type & is a by reference type!", N, Parent_Type);
3381 return True;
3382 end if;
3383 end if;
3385 -- No error, link item into head of chain of rep items for the entity
3387 Record_Rep_Item (T, N);
3388 return False;
3389 end Rep_Item_Too_Late;
3391 -------------------------
3392 -- Same_Representation --
3393 -------------------------
3395 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
3396 T1 : constant Entity_Id := Underlying_Type (Typ1);
3397 T2 : constant Entity_Id := Underlying_Type (Typ2);
3399 begin
3400 -- A quick check, if base types are the same, then we definitely have
3401 -- the same representation, because the subtype specific representation
3402 -- attributes (Size and Alignment) do not affect representation from
3403 -- the point of view of this test.
3405 if Base_Type (T1) = Base_Type (T2) then
3406 return True;
3408 elsif Is_Private_Type (Base_Type (T2))
3409 and then Base_Type (T1) = Full_View (Base_Type (T2))
3410 then
3411 return True;
3412 end if;
3414 -- Tagged types never have differing representations
3416 if Is_Tagged_Type (T1) then
3417 return True;
3418 end if;
3420 -- Representations are definitely different if conventions differ
3422 if Convention (T1) /= Convention (T2) then
3423 return False;
3424 end if;
3426 -- Representations are different if component alignments differ
3428 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
3429 and then
3430 (Is_Record_Type (T2) or else Is_Array_Type (T2))
3431 and then Component_Alignment (T1) /= Component_Alignment (T2)
3432 then
3433 return False;
3434 end if;
3436 -- For arrays, the only real issue is component size. If we know the
3437 -- component size for both arrays, and it is the same, then that's
3438 -- good enough to know we don't have a change of representation.
3440 if Is_Array_Type (T1) then
3441 if Known_Component_Size (T1)
3442 and then Known_Component_Size (T2)
3443 and then Component_Size (T1) = Component_Size (T2)
3444 then
3445 return True;
3446 end if;
3447 end if;
3449 -- Types definitely have same representation if neither has non-standard
3450 -- representation since default representations are always consistent.
3451 -- If only one has non-standard representation, and the other does not,
3452 -- then we consider that they do not have the same representation. They
3453 -- might, but there is no way of telling early enough.
3455 if Has_Non_Standard_Rep (T1) then
3456 if not Has_Non_Standard_Rep (T2) then
3457 return False;
3458 end if;
3459 else
3460 return not Has_Non_Standard_Rep (T2);
3461 end if;
3463 -- Here the two types both have non-standard representation, and we
3464 -- need to determine if they have the same non-standard representation
3466 -- For arrays, we simply need to test if the component sizes are the
3467 -- same. Pragma Pack is reflected in modified component sizes, so this
3468 -- check also deals with pragma Pack.
3470 if Is_Array_Type (T1) then
3471 return Component_Size (T1) = Component_Size (T2);
3473 -- Tagged types always have the same representation, because it is not
3474 -- possible to specify different representations for common fields.
3476 elsif Is_Tagged_Type (T1) then
3477 return True;
3479 -- Case of record types
3481 elsif Is_Record_Type (T1) then
3483 -- Packed status must conform
3485 if Is_Packed (T1) /= Is_Packed (T2) then
3486 return False;
3488 -- Otherwise we must check components. Typ2 maybe a constrained
3489 -- subtype with fewer components, so we compare the components
3490 -- of the base types.
3492 else
3493 Record_Case : declare
3494 CD1, CD2 : Entity_Id;
3496 function Same_Rep return Boolean;
3497 -- CD1 and CD2 are either components or discriminants. This
3498 -- function tests whether the two have the same representation
3500 --------------
3501 -- Same_Rep --
3502 --------------
3504 function Same_Rep return Boolean is
3505 begin
3506 if No (Component_Clause (CD1)) then
3507 return No (Component_Clause (CD2));
3509 else
3510 return
3511 Present (Component_Clause (CD2))
3512 and then
3513 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
3514 and then
3515 Esize (CD1) = Esize (CD2);
3516 end if;
3517 end Same_Rep;
3519 -- Start processing for Record_Case
3521 begin
3522 if Has_Discriminants (T1) then
3523 CD1 := First_Discriminant (T1);
3524 CD2 := First_Discriminant (T2);
3526 -- The number of discriminants may be different if the
3527 -- derived type has fewer (constrained by values). The
3528 -- invisible discriminants retain the representation of
3529 -- the original, so the discrepancy does not per se
3530 -- indicate a different representation.
3532 while Present (CD1)
3533 and then Present (CD2)
3534 loop
3535 if not Same_Rep then
3536 return False;
3537 else
3538 Next_Discriminant (CD1);
3539 Next_Discriminant (CD2);
3540 end if;
3541 end loop;
3542 end if;
3544 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
3545 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
3547 while Present (CD1) loop
3548 if not Same_Rep then
3549 return False;
3550 else
3551 Next_Component (CD1);
3552 Next_Component (CD2);
3553 end if;
3554 end loop;
3556 return True;
3557 end Record_Case;
3558 end if;
3560 -- For enumeration types, we must check each literal to see if the
3561 -- representation is the same. Note that we do not permit enumeration
3562 -- reprsentation clauses for Character and Wide_Character, so these
3563 -- cases were already dealt with.
3565 elsif Is_Enumeration_Type (T1) then
3567 Enumeration_Case : declare
3568 L1, L2 : Entity_Id;
3570 begin
3571 L1 := First_Literal (T1);
3572 L2 := First_Literal (T2);
3574 while Present (L1) loop
3575 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
3576 return False;
3577 else
3578 Next_Literal (L1);
3579 Next_Literal (L2);
3580 end if;
3581 end loop;
3583 return True;
3585 end Enumeration_Case;
3587 -- Any other types have the same representation for these purposes
3589 else
3590 return True;
3591 end if;
3592 end Same_Representation;
3594 --------------------
3595 -- Set_Enum_Esize --
3596 --------------------
3598 procedure Set_Enum_Esize (T : Entity_Id) is
3599 Lo : Uint;
3600 Hi : Uint;
3601 Sz : Nat;
3603 begin
3604 Init_Alignment (T);
3606 -- Find the minimum standard size (8,16,32,64) that fits
3608 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
3609 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
3611 if Lo < 0 then
3612 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
3613 Sz := Standard_Character_Size; -- May be > 8 on some targets
3615 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
3616 Sz := 16;
3618 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
3619 Sz := 32;
3621 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
3622 Sz := 64;
3623 end if;
3625 else
3626 if Hi < Uint_2**08 then
3627 Sz := Standard_Character_Size; -- May be > 8 on some targets
3629 elsif Hi < Uint_2**16 then
3630 Sz := 16;
3632 elsif Hi < Uint_2**32 then
3633 Sz := 32;
3635 else pragma Assert (Hi < Uint_2**63);
3636 Sz := 64;
3637 end if;
3638 end if;
3640 -- That minimum is the proper size unless we have a foreign convention
3641 -- and the size required is 32 or less, in which case we bump the size
3642 -- up to 32. This is required for C and C++ and seems reasonable for
3643 -- all other foreign conventions.
3645 if Has_Foreign_Convention (T)
3646 and then Esize (T) < Standard_Integer_Size
3647 then
3648 Init_Esize (T, Standard_Integer_Size);
3650 else
3651 Init_Esize (T, Sz);
3652 end if;
3653 end Set_Enum_Esize;
3655 -----------------------------------
3656 -- Validate_Unchecked_Conversion --
3657 -----------------------------------
3659 procedure Validate_Unchecked_Conversion
3660 (N : Node_Id;
3661 Act_Unit : Entity_Id)
3663 Source : Entity_Id;
3664 Target : Entity_Id;
3665 Vnode : Node_Id;
3667 begin
3668 -- Obtain source and target types. Note that we call Ancestor_Subtype
3669 -- here because the processing for generic instantiation always makes
3670 -- subtypes, and we want the original frozen actual types.
3672 -- If we are dealing with private types, then do the check on their
3673 -- fully declared counterparts if the full declarations have been
3674 -- encountered (they don't have to be visible, but they must exist!)
3676 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
3678 if Is_Private_Type (Source)
3679 and then Present (Underlying_Type (Source))
3680 then
3681 Source := Underlying_Type (Source);
3682 end if;
3684 Target := Ancestor_Subtype (Etype (Act_Unit));
3686 -- If either type is generic, the instantiation happens within a
3687 -- generic unit, and there is nothing to check. The proper check
3688 -- will happen when the enclosing generic is instantiated.
3690 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
3691 return;
3692 end if;
3694 if Is_Private_Type (Target)
3695 and then Present (Underlying_Type (Target))
3696 then
3697 Target := Underlying_Type (Target);
3698 end if;
3700 -- Source may be unconstrained array, but not target
3702 if Is_Array_Type (Target)
3703 and then not Is_Constrained (Target)
3704 then
3705 Error_Msg_N
3706 ("unchecked conversion to unconstrained array not allowed", N);
3707 return;
3708 end if;
3710 -- Make entry in unchecked conversion table for later processing
3711 -- by Validate_Unchecked_Conversions, which will check sizes and
3712 -- alignments (using values set by the back-end where possible).
3713 -- This is only done if the appropriate warning is active
3715 if Warn_On_Unchecked_Conversion then
3716 Unchecked_Conversions.Append
3717 (New_Val => UC_Entry'
3718 (Enode => N,
3719 Source => Source,
3720 Target => Target));
3722 -- If both sizes are known statically now, then back end annotation
3723 -- is not required to do a proper check but if either size is not
3724 -- known statically, then we need the annotation.
3726 if Known_Static_RM_Size (Source)
3727 and then Known_Static_RM_Size (Target)
3728 then
3729 null;
3730 else
3731 Back_Annotate_Rep_Info := True;
3732 end if;
3733 end if;
3735 -- If unchecked conversion to access type, and access type is
3736 -- declared in the same unit as the unchecked conversion, then
3737 -- set the No_Strict_Aliasing flag (no strict aliasing is
3738 -- implicit in this situation).
3740 if Is_Access_Type (Target) and then
3741 In_Same_Source_Unit (Target, N)
3742 then
3743 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
3744 end if;
3746 -- Generate N_Validate_Unchecked_Conversion node for back end in
3747 -- case the back end needs to perform special validation checks.
3749 -- Shouldn't this be in exp_ch13, since the check only gets done
3750 -- if we have full expansion and the back end is called ???
3752 Vnode :=
3753 Make_Validate_Unchecked_Conversion (Sloc (N));
3754 Set_Source_Type (Vnode, Source);
3755 Set_Target_Type (Vnode, Target);
3757 -- If the unchecked conversion node is in a list, just insert before
3758 -- it. If not we have some strange case, not worth bothering about.
3760 if Is_List_Member (N) then
3761 Insert_After (N, Vnode);
3762 end if;
3763 end Validate_Unchecked_Conversion;
3765 ------------------------------------
3766 -- Validate_Unchecked_Conversions --
3767 ------------------------------------
3769 procedure Validate_Unchecked_Conversions is
3770 begin
3771 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
3772 declare
3773 T : UC_Entry renames Unchecked_Conversions.Table (N);
3775 Enode : constant Node_Id := T.Enode;
3776 Source : constant Entity_Id := T.Source;
3777 Target : constant Entity_Id := T.Target;
3779 Source_Siz : Uint;
3780 Target_Siz : Uint;
3782 begin
3783 -- This validation check, which warns if we have unequal sizes
3784 -- for unchecked conversion, and thus potentially implementation
3785 -- dependent semantics, is one of the few occasions on which we
3786 -- use the official RM size instead of Esize. See description
3787 -- in Einfo "Handling of Type'Size Values" for details.
3789 if Serious_Errors_Detected = 0
3790 and then Known_Static_RM_Size (Source)
3791 and then Known_Static_RM_Size (Target)
3792 then
3793 Source_Siz := RM_Size (Source);
3794 Target_Siz := RM_Size (Target);
3796 if Source_Siz /= Target_Siz then
3797 Error_Msg_N
3798 ("types for unchecked conversion have different sizes?",
3799 Enode);
3801 if All_Errors_Mode then
3802 Error_Msg_Name_1 := Chars (Source);
3803 Error_Msg_Uint_1 := Source_Siz;
3804 Error_Msg_Name_2 := Chars (Target);
3805 Error_Msg_Uint_2 := Target_Siz;
3806 Error_Msg_N
3807 ("\size of % is ^, size of % is ^?", Enode);
3809 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
3811 if Is_Discrete_Type (Source)
3812 and then Is_Discrete_Type (Target)
3813 then
3814 if Source_Siz > Target_Siz then
3815 Error_Msg_N
3816 ("\^ high order bits of source will be ignored?",
3817 Enode);
3819 elsif Is_Unsigned_Type (Source) then
3820 Error_Msg_N
3821 ("\source will be extended with ^ high order " &
3822 "zero bits?", Enode);
3824 else
3825 Error_Msg_N
3826 ("\source will be extended with ^ high order " &
3827 "sign bits?",
3828 Enode);
3829 end if;
3831 elsif Source_Siz < Target_Siz then
3832 if Is_Discrete_Type (Target) then
3833 if Bytes_Big_Endian then
3834 Error_Msg_N
3835 ("\target value will include ^ undefined " &
3836 "low order bits?",
3837 Enode);
3838 else
3839 Error_Msg_N
3840 ("\target value will include ^ undefined " &
3841 "high order bits?",
3842 Enode);
3843 end if;
3845 else
3846 Error_Msg_N
3847 ("\^ trailing bits of target value will be " &
3848 "undefined?", Enode);
3849 end if;
3851 else pragma Assert (Source_Siz > Target_Siz);
3852 Error_Msg_N
3853 ("\^ trailing bits of source will be ignored?",
3854 Enode);
3855 end if;
3856 end if;
3857 end if;
3858 end if;
3860 -- If both types are access types, we need to check the alignment.
3861 -- If the alignment of both is specified, we can do it here.
3863 if Serious_Errors_Detected = 0
3864 and then Ekind (Source) in Access_Kind
3865 and then Ekind (Target) in Access_Kind
3866 and then Target_Strict_Alignment
3867 and then Present (Designated_Type (Source))
3868 and then Present (Designated_Type (Target))
3869 then
3870 declare
3871 D_Source : constant Entity_Id := Designated_Type (Source);
3872 D_Target : constant Entity_Id := Designated_Type (Target);
3874 begin
3875 if Known_Alignment (D_Source)
3876 and then Known_Alignment (D_Target)
3877 then
3878 declare
3879 Source_Align : constant Uint := Alignment (D_Source);
3880 Target_Align : constant Uint := Alignment (D_Target);
3882 begin
3883 if Source_Align < Target_Align
3884 and then not Is_Tagged_Type (D_Source)
3885 then
3886 Error_Msg_Uint_1 := Target_Align;
3887 Error_Msg_Uint_2 := Source_Align;
3888 Error_Msg_Node_2 := D_Source;
3889 Error_Msg_NE
3890 ("alignment of & (^) is stricter than " &
3891 "alignment of & (^)?", Enode, D_Target);
3893 if All_Errors_Mode then
3894 Error_Msg_N
3895 ("\resulting access value may have invalid " &
3896 "alignment?", Enode);
3897 end if;
3898 end if;
3899 end;
3900 end if;
3901 end;
3902 end if;
3903 end;
3904 end loop;
3905 end Validate_Unchecked_Conversions;
3907 end Sem_Ch13;