1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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
;
34 with Nlists
; use Nlists
;
35 with Nmake
; use Nmake
;
37 with Restrict
; use Restrict
;
38 with Rident
; use Rident
;
39 with Rtsfind
; use Rtsfind
;
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
;
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
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
115 procedure New_Stream_Procedure
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
144 package Unchecked_Conversions
is new Table
.Table
(
145 Table_Component_Type
=> UC_Entry
,
146 Table_Index_Type
=> Int
,
147 Table_Low_Bound
=> 1,
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
158 if Nkind
(N
) = N_Attribute_Reference
159 and then Attribute_Name
(N
) = Name_Address
162 Nam
: Node_Id
:= Prefix
(N
);
165 or else Nkind
(Nam
) = N_Selected_Component
166 or else Nkind
(Nam
) = N_Indexed_Component
171 if Is_Entity_Name
(Nam
) then
178 end Address_Aliased_Entity
;
180 --------------------------------------
181 -- Alignment_Check_For_Esize_Change --
182 --------------------------------------
184 procedure Alignment_Check_For_Esize_Change
(Typ
: Entity_Id
) is
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
195 Init_Alignment
(Typ
);
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
208 Check_Restriction
(No_Obsolescent_Features
, N
);
210 if Warn_On_Obsolescent_Feature
then
212 ("at clause is an obsolescent feature ('R'M 'J.7(2))?", N
);
214 ("\use address attribute definition clause instead?", 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
);
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
;
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
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
);
275 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
279 F
:= First_Formal
(Subp
);
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
))
289 if not Is_Function
then
293 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
294 (False => E_In_Parameter
,
295 True => E_Out_Parameter
);
297 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
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
318 if not Is_Type
(U_Ent
) then
319 Error_Msg_N
("local name must be a subtype", Nam
);
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
);
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
);
341 Get_First_Interp
(Expr
, I
, It
);
343 while Present
(It
.Nam
) loop
344 if Has_Good_Profile
(It
.Nam
) then
349 Get_Next_Interp
(I
, It
);
354 if Present
(Subp
) then
355 if Is_Abstract
(Subp
) then
356 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
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
);
366 New_Stream_Procedure
(N
, U_Ent
, Subp
, TSS_Nam
,
371 Error_Msg_Name_1
:= Attr
;
372 Error_Msg_N
("incorrect expression for% attribute", Expr
);
374 end Analyze_Stream_TSS_Definition
;
376 -- Start of processing for Analyze_Attribute_Definition_Clause
382 if Rep_Item_Too_Early
(Ent
, N
) then
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
))
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.
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
);
409 Set_Entity
(Nam
, Ent
);
412 U_Ent
:= Underlying_Type
(Ent
);
415 -- Complete other routine error checks
417 if Etype
(Nam
) = Any_Type
then
420 elsif Scope
(Ent
) /= Current_Scope
then
421 Error_Msg_N
("entity must be declared in this scope", Nam
);
424 elsif No
(U_Ent
) then
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
)
433 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
437 -- Switch on particular attribute
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
458 ("address clause cannot be given " &
459 "for overloaded subprogram",
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
476 ("entry address must be specified in task spec", Nam
);
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
))
487 ("?entry address declared for entry in task type", N
);
489 ("\?only one task can be declared of this type", N
);
492 Check_Restriction
(No_Obsolescent_Features
, N
);
494 if Warn_On_Obsolescent_Feature
then
496 ("attaching interrupt to task entry is an " &
497 "obsolescent feature ('R'M 'J.7.1)?", N
);
499 ("\use interrupt procedure instead?", N
);
502 -- Case of an address clause for a controlled object:
503 -- erroneous execution.
505 elsif Is_Controlled
(Etype
(U_Ent
)) then
507 ("?controlled object& must not be overlaid", Nam
, U_Ent
);
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
517 Ekind
(U_Ent
) = E_Variable
519 Ekind
(U_Ent
) = E_Constant
522 Expr
: constant Node_Id
:= Expression
(N
);
523 Aent
: constant Entity_Id
:= Address_Aliased_Entity
(Expr
);
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
531 ("cannot export object with address clause", Nam
);
533 -- Overlaying controlled objects is erroneous
536 and then Is_Controlled
(Etype
(Aent
))
539 ("?controlled object must not be overlaid", Expr
);
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
));
547 and then Ekind
(U_Ent
) = E_Constant
548 and then Ekind
(Aent
) /= E_Constant
550 Error_Msg_N
("constant overlays a variable?", Expr
);
552 elsif Present
(Renamed_Object
(U_Ent
)) then
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);
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;
589 -- for B'Address use A;
591 -- In this case we also mark K as volatile
593 if Is_Entity_Name
(Expr
) then
595 Ent
: constant Entity_Id
:= Entity
(Expr
);
596 Decl
: constant Node_Id
:= Declaration_Node
(Ent
);
599 if Ekind
(Ent
) = E_Constant
600 and then Nkind
(Decl
) = N_Object_Declaration
601 and then Present
(Expression
(Decl
))
603 Mark_Aliased_Address_As_Volatile
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
618 ("& cannot be exported if an address clause is given",
621 ("\define and export a variable " &
622 "that holds its address instead",
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
);
638 -- Not a valid entity for an address clause
641 Error_Msg_N
("address cannot be given for &", Nam
);
649 -- Alignment attribute definition clause
651 when Attribute_Alignment
=> Alignment_Block
: declare
652 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
657 if not Is_Type
(U_Ent
)
658 and then Ekind
(U_Ent
) /= E_Variable
659 and then Ekind
(U_Ent
) /= E_Constant
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
);
677 -- Bit_Order attribute definition clause
679 when Attribute_Bit_Order
=> Bit_Order
: declare
681 if not Is_Record_Type
(U_Ent
) then
683 ("Bit_Order can only be defined for record type", Nam
);
686 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
688 if Etype
(Expr
) = Any_Type
then
691 elsif not Is_Static_Expression
(Expr
) then
693 ("Bit_Order requires static expression!", Expr
);
696 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
697 Set_Reverse_Bit_Order
(U_Ent
, True);
707 -- Component_Size attribute definition clause
709 when Attribute_Component_Size
=> Component_Size_Case
: declare
710 Csize
: constant Uint
:= Static_Integer
(Expr
);
713 New_Ctyp
: Entity_Id
;
717 if not Is_Array_Type
(U_Ent
) then
718 Error_Msg_N
("component size requires array type", Nam
);
722 Btype
:= Base_Type
(U_Ent
);
724 if Has_Component_Size_Clause
(Btype
) then
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
)
737 ("component size incorrect for aliased components", N
);
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.
749 Make_Defining_Identifier
(Loc
,
750 Chars
=> New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
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
);
772 Set_Component_Size
(Btype
, Csize
);
773 Set_Has_Component_Size_Clause
(Btype
, True);
774 Set_Has_Non_Standard_Rep
(Btype
, True);
776 end Component_Size_Case
;
782 when Attribute_External_Tag
=> External_Tag
:
784 if not Is_Tagged_Type
(U_Ent
) then
785 Error_Msg_N
("should be a tagged type", Nam
);
788 Analyze_And_Resolve
(Expr
, Standard_String
);
790 if not Is_Static_Expression
(Expr
) then
792 ("static string required for tag name!", Nam
);
795 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
802 when Attribute_Input
=>
803 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
804 Set_Has_Specified_Stream_Input
(Ent
);
810 -- Machine radix attribute definition clause
812 when Attribute_Machine_Radix
=> Machine_Radix
: declare
813 Radix
: constant Uint
:= Static_Integer
(Expr
);
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
));
829 elsif Radix
= 10 then
830 Set_Machine_Radix_10
(U_Ent
);
832 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
841 -- Object_Size attribute definition clause
843 when Attribute_Object_Size
=> Object_Size
: declare
844 Size
: constant Uint
:= Static_Integer
(Expr
);
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
);
855 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
863 UI_Mod
(Size
, 64) /= 0
866 ("Object_Size must be 8, 16, 32, or multiple of 64",
870 Set_Esize
(U_Ent
, Size
);
871 Set_Has_Object_Size_Clause
(U_Ent
);
872 Alignment_Check_For_Esize_Change
(U_Ent
);
880 when Attribute_Output
=>
881 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
882 Set_Has_Specified_Stream_Output
(Ent
);
888 when Attribute_Read
=>
889 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
890 Set_Has_Specified_Stream_Read
(Ent
);
896 -- Size attribute definition clause
898 when Attribute_Size
=> Size
: declare
899 Size
: constant Uint
:= Static_Integer
(Expr
);
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
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
)
919 ("size cannot be given for unconstrained array", Nam
);
921 elsif Size
/= No_Uint
then
922 if Is_Type
(U_Ent
) then
925 Etyp
:= Etype
(U_Ent
);
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
)
938 Check_Size
(Expr
, Etyp
, Size
, Biased
);
939 Set_Has_Biased_Representation
(U_Ent
, Biased
);
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);
959 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
962 -- For all other types, object size = value size. The
963 -- backend will adjust as needed.
966 Set_Esize
(U_Ent
, Size
);
969 Alignment_Check_For_Esize_Change
(U_Ent
);
971 -- For objects, set Esize only
974 if Is_Elementary_Type
(Etyp
) then
975 if Size
/= System_Storage_Unit
977 Size
/= System_Storage_Unit
* 2
979 Size
/= System_Storage_Unit
* 4
981 Size
/= System_Storage_Unit
* 8
983 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
985 ("size for primitive object must be a power of 2"
986 & " and at least ^", N
);
990 Set_Esize
(U_Ent
, Size
);
993 Set_Has_Size_Clause
(U_Ent
);
1001 -- Small attribute definition clause
1003 when Attribute_Small
=> Small
: declare
1004 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
1008 Analyze_And_Resolve
(Expr
, Any_Real
);
1010 if Etype
(Expr
) = Any_Type
then
1013 elsif not Is_Static_Expression
(Expr
) then
1014 Flag_Non_Static_Expr
1015 ("small requires static expression!", Expr
);
1019 Small
:= Expr_Value_R
(Expr
);
1021 if Small
<= Ureal_0
then
1022 Error_Msg_N
("small value must be greater than zero", Expr
);
1028 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
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
1037 ("small value must not be greater then delta value", Nam
);
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
);
1052 -- Storage_Size attribute definition clause
1054 when Attribute_Storage_Size
=> Storage_Size
: declare
1055 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
1059 if Is_Task_Type
(U_Ent
) then
1060 Check_Restriction
(No_Obsolescent_Features
, N
);
1062 if Warn_On_Obsolescent_Feature
then
1064 ("storage size clause for task is an " &
1065 "obsolescent feature ('R'M 'J.9)?", N
);
1067 ("\use Storage_Size pragma instead?", N
);
1073 if not Is_Access_Type
(U_Ent
)
1074 and then Ekind
(U_Ent
) /= E_Task_Type
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
1080 ("storage size cannot be given for a derived access type",
1083 elsif Has_Storage_Size_Clause
(Btype
) then
1084 Error_Msg_N
("storage size already given for &", Nam
);
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
);
1096 if Compile_Time_Known_Value
(Expr
)
1097 and then Expr_Value
(Expr
) = 0
1099 Set_No_Pool_Assigned
(Btype
);
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
);
1108 ("Storage_Size already specified#", Nam
);
1113 Set_Has_Storage_Size_Clause
(Btype
);
1121 -- Storage_Pool attribute definition clause
1123 when Attribute_Storage_Pool
=> Storage_Pool
: declare
1128 if Ekind
(U_Ent
) /= E_Access_Type
1129 and then Ekind
(U_Ent
) /= E_General_Access_Type
1132 "storage pool can only be given for access types", Nam
);
1135 elsif Is_Derived_Type
(U_Ent
) then
1137 ("storage pool cannot be given for a derived access type",
1140 elsif Has_Storage_Size_Clause
(U_Ent
) then
1141 Error_Msg_N
("storage size already given for &", Nam
);
1144 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
1145 Error_Msg_N
("storage pool already given for &", Nam
);
1150 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
1152 if Nkind
(Expr
) = N_Type_Conversion
then
1153 T
:= Etype
(Expression
(Expr
));
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
);
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
)
1180 Make_Defining_Identifier
(Loc
,
1181 Chars
=> New_Internal_Name
('P'));
1184 Rnode
: constant Node_Id
:=
1185 Make_Object_Renaming_Declaration
(Loc
,
1186 Defining_Identifier
=> Pool
,
1188 New_Occurrence_Of
(Etype
(Expr
), Loc
),
1192 Insert_Before
(N
, Rnode
);
1194 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
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
))
1206 Pool
:= Entity
(Renamed_Object
(Pool
));
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
)))
1213 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
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
1222 Pool
:= Entity
(Expression
(Expr
));
1223 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1226 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
1235 when Attribute_Stream_Size
=> Stream_Size
: declare
1236 Size
: constant Uint
:= Static_Integer
(Expr
);
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
1245 Size
/= System_Storage_Unit
* 2
1247 Size
/= System_Storage_Unit
* 4
1249 Size
/= System_Storage_Unit
* 8
1251 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
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
);
1259 ("stream size for elementary type must be a"
1260 & " power of 2 and at least ^", N
);
1263 Set_Has_Stream_Size_Clause
(U_Ent
);
1266 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
1274 -- Value_Size attribute definition clause
1276 when Attribute_Value_Size
=> Value_Size
: declare
1277 Size
: constant Uint
:= Static_Integer
(Expr
);
1281 if not Is_Type
(U_Ent
) then
1282 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
1285 (Get_Attribute_Definition_Clause
1286 (U_Ent
, Attribute_Value_Size
))
1288 Error_Msg_N
("Value_Size already given for &", Nam
);
1291 if Is_Elementary_Type
(U_Ent
) then
1292 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
1293 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1296 Set_RM_Size
(U_Ent
, Size
);
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
1312 ("attribute& cannot be set with definition clause", N
);
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
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
;
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
1346 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
1347 Error_Msg_N
("incorrect type for code statement", N
);
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
1358 ("code statement can only appear in body of subprogram", N
);
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
1371 ("exception handlers not permitted in machine code subprogram",
1372 First
(Exception_Handlers
(HSS
)));
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
1388 ("this declaration not allowed in machine code subprogram",
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
1407 ("this statement is not allowed in machine code subprogram",
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
;
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
));
1437 -- First some basic error checks
1440 Enumtype
:= Entity
(Ident
);
1442 if Enumtype
= Any_Type
1443 or else Rep_Item_Too_Early
(Enumtype
, N
)
1447 Enumtype
:= Underlying_Type
(Enumtype
);
1450 if not Is_Enumeration_Type
(Enumtype
) then
1452 ("enumeration type required, found}",
1453 Ident
, First_Subtype
(Enumtype
));
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
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
);
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
);
1476 -- Ignore duplicate rep clause
1478 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
1479 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
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
1488 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
1491 -- All tests passed, so set rep clause in place
1494 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
1495 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
1498 -- Now we process the aggregate. Note that we don't use the normal
1499 -- aggregate code for this purpose, because we don't want any of the
1500 -- normal expansion activities, and a number of special semantic
1501 -- rules apply (including the component type being any integer type)
1503 -- Badent signals that we found some incorrect entries processing
1504 -- the list. The final checks for completeness and ordering are
1505 -- skipped in this case.
1507 Elit
:= First_Literal
(Enumtype
);
1509 -- First the positional entries if any
1511 if Present
(Expressions
(Aggr
)) then
1512 Expr
:= First
(Expressions
(Aggr
));
1513 while Present
(Expr
) loop
1515 Error_Msg_N
("too many entries in aggregate", Expr
);
1519 Val
:= Static_Integer
(Expr
);
1521 if Val
= No_Uint
then
1524 elsif Val
< Lo
or else Hi
< Val
then
1525 Error_Msg_N
("value outside permitted range", Expr
);
1529 Set_Enumeration_Rep
(Elit
, Val
);
1530 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
1536 -- Now process the named entries if present
1538 if Present
(Component_Associations
(Aggr
)) then
1539 Assoc
:= First
(Component_Associations
(Aggr
));
1540 while Present
(Assoc
) loop
1541 Choice
:= First
(Choices
(Assoc
));
1543 if Present
(Next
(Choice
)) then
1545 ("multiple choice not allowed here", Next
(Choice
));
1549 if Nkind
(Choice
) = N_Others_Choice
then
1550 Error_Msg_N
("others choice not allowed here", Choice
);
1553 elsif Nkind
(Choice
) = N_Range
then
1554 -- ??? should allow zero/one element range here
1555 Error_Msg_N
("range not allowed here", Choice
);
1559 Analyze_And_Resolve
(Choice
, Enumtype
);
1561 if Is_Entity_Name
(Choice
)
1562 and then Is_Type
(Entity
(Choice
))
1564 Error_Msg_N
("subtype name not allowed here", Choice
);
1566 -- ??? should allow static subtype with zero/one entry
1568 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
1569 if not Is_Static_Expression
(Choice
) then
1570 Flag_Non_Static_Expr
1571 ("non-static expression used for choice!", Choice
);
1575 Elit
:= Expr_Value_E
(Choice
);
1577 if Present
(Enumeration_Rep_Expr
(Elit
)) then
1578 Error_Msg_Sloc
:= Sloc
(Enumeration_Rep_Expr
(Elit
));
1580 ("representation for& previously given#",
1585 Set_Enumeration_Rep_Expr
(Elit
, Choice
);
1587 Expr
:= Expression
(Assoc
);
1588 Val
:= Static_Integer
(Expr
);
1590 if Val
= No_Uint
then
1593 elsif Val
< Lo
or else Hi
< Val
then
1594 Error_Msg_N
("value outside permitted range", Expr
);
1598 Set_Enumeration_Rep
(Elit
, Val
);
1607 -- Aggregate is fully processed. Now we check that a full set of
1608 -- representations was given, and that they are in range and in order.
1609 -- These checks are only done if no other errors occurred.
1615 Elit
:= First_Literal
(Enumtype
);
1616 while Present
(Elit
) loop
1617 if No
(Enumeration_Rep_Expr
(Elit
)) then
1618 Error_Msg_NE
("missing representation for&!", N
, Elit
);
1621 Val
:= Enumeration_Rep
(Elit
);
1623 if Min
= No_Uint
then
1627 if Val
/= No_Uint
then
1628 if Max
/= No_Uint
and then Val
<= Max
then
1630 ("enumeration value for& not ordered!",
1631 Enumeration_Rep_Expr
(Elit
), Elit
);
1637 -- If there is at least one literal whose representation
1638 -- is not equal to the Pos value, then note that this
1639 -- enumeration type has a non-standard representation.
1641 if Val
/= Enumeration_Pos
(Elit
) then
1642 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
1649 -- Now set proper size information
1652 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
1655 if Has_Size_Clause
(Enumtype
) then
1656 if Esize
(Enumtype
) >= Minsize
then
1661 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
1663 if Esize
(Enumtype
) < Minsize
then
1664 Error_Msg_N
("previously given size is too small", N
);
1667 Set_Has_Biased_Representation
(Enumtype
);
1672 Set_RM_Size
(Enumtype
, Minsize
);
1673 Set_Enum_Esize
(Enumtype
);
1676 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
1677 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
1678 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
1682 -- We repeat the too late test in case it froze itself!
1684 if Rep_Item_Too_Late
(Enumtype
, N
) then
1687 end Analyze_Enumeration_Representation_Clause
;
1689 ----------------------------
1690 -- Analyze_Free_Statement --
1691 ----------------------------
1693 procedure Analyze_Free_Statement
(N
: Node_Id
) is
1695 Analyze
(Expression
(N
));
1696 end Analyze_Free_Statement
;
1698 ------------------------------------------
1699 -- Analyze_Record_Representation_Clause --
1700 ------------------------------------------
1702 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
1703 Loc
: constant Source_Ptr
:= Sloc
(N
);
1704 Ident
: constant Node_Id
:= Identifier
(N
);
1705 Rectype
: Entity_Id
;
1711 Hbit
: Uint
:= Uint_0
;
1716 Max_Bit_So_Far
: Uint
;
1717 -- Records the maximum bit position so far. If all field positions
1718 -- are monotonically increasing, then we can skip the circuit for
1719 -- checking for overlap, since no overlap is possible.
1721 Overlap_Check_Required
: Boolean;
1722 -- Used to keep track of whether or not an overlap check is required
1724 Ccount
: Natural := 0;
1725 -- Number of component clauses in record rep clause
1729 Rectype
:= Entity
(Ident
);
1731 if Rectype
= Any_Type
1732 or else Rep_Item_Too_Early
(Rectype
, N
)
1736 Rectype
:= Underlying_Type
(Rectype
);
1739 -- First some basic error checks
1741 if not Is_Record_Type
(Rectype
) then
1743 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
1746 elsif Is_Unchecked_Union
(Rectype
) then
1748 ("record rep clause not allowed for Unchecked_Union", N
);
1750 elsif Scope
(Rectype
) /= Current_Scope
then
1751 Error_Msg_N
("type must be declared in this scope", N
);
1754 elsif not Is_First_Subtype
(Rectype
) then
1755 Error_Msg_N
("cannot give record rep clause for subtype", N
);
1758 elsif Has_Record_Rep_Clause
(Rectype
) then
1759 Error_Msg_N
("duplicate record rep clause ignored", N
);
1762 elsif Rep_Item_Too_Late
(Rectype
, N
) then
1766 if Present
(Mod_Clause
(N
)) then
1768 Loc
: constant Source_Ptr
:= Sloc
(N
);
1769 M
: constant Node_Id
:= Mod_Clause
(N
);
1770 P
: constant List_Id
:= Pragmas_Before
(M
);
1774 pragma Warnings
(Off
, Mod_Val
);
1777 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
1779 if Warn_On_Obsolescent_Feature
then
1781 ("mod clause is an obsolescent feature ('R'M 'J.8)?", N
);
1783 ("\use alignment attribute definition clause instead?", N
);
1790 -- In ASIS_Mode mode, expansion is disabled, but we must
1791 -- convert the Mod clause into an alignment clause anyway, so
1792 -- that the back-end can compute and back-annotate properly the
1793 -- size and alignment of types that may include this record.
1795 if Operating_Mode
= Check_Semantics
1799 Make_Attribute_Definition_Clause
(Loc
,
1800 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
1801 Chars
=> Name_Alignment
,
1802 Expression
=> Relocate_Node
(Expression
(M
)));
1804 Set_From_At_Mod
(AtM_Nod
);
1805 Insert_After
(N
, AtM_Nod
);
1806 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
1807 Set_Mod_Clause
(N
, Empty
);
1810 -- Get the alignment value to perform error checking
1812 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
1818 -- Clear any existing component clauses for the type (this happens
1819 -- with derived types, where we are now overriding the original)
1821 Fent
:= First_Entity
(Rectype
);
1824 while Present
(Comp
) loop
1825 if Ekind
(Comp
) = E_Component
1826 or else Ekind
(Comp
) = E_Discriminant
1828 Set_Component_Clause
(Comp
, Empty
);
1834 -- All done if no component clauses
1836 CC
:= First
(Component_Clauses
(N
));
1842 -- If a tag is present, then create a component clause that places
1843 -- it at the start of the record (otherwise gigi may place it after
1844 -- other fields that have rep clauses).
1846 if Nkind
(Fent
) = N_Defining_Identifier
1847 and then Chars
(Fent
) = Name_uTag
1849 Set_Component_Bit_Offset
(Fent
, Uint_0
);
1850 Set_Normalized_Position
(Fent
, Uint_0
);
1851 Set_Normalized_First_Bit
(Fent
, Uint_0
);
1852 Set_Normalized_Position_Max
(Fent
, Uint_0
);
1853 Init_Esize
(Fent
, System_Address_Size
);
1855 Set_Component_Clause
(Fent
,
1856 Make_Component_Clause
(Loc
,
1858 Make_Identifier
(Loc
,
1859 Chars
=> Name_uTag
),
1862 Make_Integer_Literal
(Loc
,
1866 Make_Integer_Literal
(Loc
,
1870 Make_Integer_Literal
(Loc
,
1871 UI_From_Int
(System_Address_Size
))));
1873 Ccount
:= Ccount
+ 1;
1876 -- A representation like this applies to the base type
1878 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
1879 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
1880 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
1882 Max_Bit_So_Far
:= Uint_Minus_1
;
1883 Overlap_Check_Required
:= False;
1885 -- Process the component clauses
1887 while Present
(CC
) loop
1889 -- If pragma, just analyze it
1891 if Nkind
(CC
) = N_Pragma
then
1894 -- Processing for real component clause
1897 Ccount
:= Ccount
+ 1;
1898 Posit
:= Static_Integer
(Position
(CC
));
1899 Fbit
:= Static_Integer
(First_Bit
(CC
));
1900 Lbit
:= Static_Integer
(Last_Bit
(CC
));
1903 and then Fbit
/= No_Uint
1904 and then Lbit
/= No_Uint
1908 ("position cannot be negative", Position
(CC
));
1912 ("first bit cannot be negative", First_Bit
(CC
));
1914 -- Values look OK, so find the corresponding record component
1915 -- Even though the syntax allows an attribute reference for
1916 -- implementation-defined components, GNAT does not allow the
1917 -- tag to get an explicit position.
1919 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
1920 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
1921 Error_Msg_N
("position of tag cannot be specified", CC
);
1923 Error_Msg_N
("illegal component name", CC
);
1927 Comp
:= First_Entity
(Rectype
);
1928 while Present
(Comp
) loop
1929 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
1935 -- Maybe component of base type that is absent from
1936 -- statically constrained first subtype.
1938 Comp
:= First_Entity
(Base_Type
(Rectype
));
1939 while Present
(Comp
) loop
1940 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
1947 ("component clause is for non-existent field", CC
);
1949 elsif Present
(Component_Clause
(Comp
)) then
1950 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
1952 ("component clause previously given#", CC
);
1955 -- Update Fbit and Lbit to the actual bit number
1957 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
1958 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
1960 if Fbit
<= Max_Bit_So_Far
then
1961 Overlap_Check_Required
:= True;
1963 Max_Bit_So_Far
:= Lbit
;
1966 if Has_Size_Clause
(Rectype
)
1967 and then Esize
(Rectype
) <= Lbit
1970 ("bit number out of range of specified size",
1973 Set_Component_Clause
(Comp
, CC
);
1974 Set_Component_Bit_Offset
(Comp
, Fbit
);
1975 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
1976 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
1977 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
1979 Set_Normalized_Position_Max
1980 (Fent
, Normalized_Position
(Fent
));
1982 if Is_Tagged_Type
(Rectype
)
1983 and then Fbit
< System_Address_Size
1986 ("component overlaps tag field of&",
1990 -- This information is also set in the corresponding
1991 -- component of the base type, found by accessing the
1992 -- Original_Record_Component link if it is present.
1994 Ocomp
:= Original_Record_Component
(Comp
);
2001 (Component_Name
(CC
),
2006 Set_Has_Biased_Representation
(Comp
, Biased
);
2008 if Present
(Ocomp
) then
2009 Set_Component_Clause
(Ocomp
, CC
);
2010 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
2011 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
2012 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
2013 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
2015 Set_Normalized_Position_Max
2016 (Ocomp
, Normalized_Position
(Ocomp
));
2018 Set_Has_Biased_Representation
2019 (Ocomp
, Has_Biased_Representation
(Comp
));
2022 if Esize
(Comp
) < 0 then
2023 Error_Msg_N
("component size is negative", CC
);
2034 -- Now that we have processed all the component clauses, check for
2035 -- overlap. We have to leave this till last, since the components
2036 -- can appear in any arbitrary order in the representation clause.
2038 -- We do not need this check if all specified ranges were monotonic,
2039 -- as recorded by Overlap_Check_Required being False at this stage.
2041 -- This first section checks if there are any overlapping entries
2042 -- at all. It does this by sorting all entries and then seeing if
2043 -- there are any overlaps. If there are none, then that is decisive,
2044 -- but if there are overlaps, they may still be OK (they may result
2045 -- from fields in different variants).
2047 if Overlap_Check_Required
then
2048 Overlap_Check1
: declare
2050 OC_Fbit
: array (0 .. Ccount
) of Uint
;
2051 -- First-bit values for component clauses, the value is the
2052 -- offset of the first bit of the field from start of record.
2053 -- The zero entry is for use in sorting.
2055 OC_Lbit
: array (0 .. Ccount
) of Uint
;
2056 -- Last-bit values for component clauses, the value is the
2057 -- offset of the last bit of the field from start of record.
2058 -- The zero entry is for use in sorting.
2060 OC_Count
: Natural := 0;
2061 -- Count of entries in OC_Fbit and OC_Lbit
2063 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
2064 -- Compare routine for Sort (See GNAT.Heap_Sort_A)
2066 procedure OC_Move
(From
: Natural; To
: Natural);
2067 -- Move routine for Sort (see GNAT.Heap_Sort_A)
2069 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
2071 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
2074 procedure OC_Move
(From
: Natural; To
: Natural) is
2076 OC_Fbit
(To
) := OC_Fbit
(From
);
2077 OC_Lbit
(To
) := OC_Lbit
(From
);
2081 CC
:= First
(Component_Clauses
(N
));
2082 while Present
(CC
) loop
2083 if Nkind
(CC
) /= N_Pragma
then
2084 Posit
:= Static_Integer
(Position
(CC
));
2085 Fbit
:= Static_Integer
(First_Bit
(CC
));
2086 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2089 and then Fbit
/= No_Uint
2090 and then Lbit
/= No_Uint
2092 OC_Count
:= OC_Count
+ 1;
2093 Posit
:= Posit
* SSU
;
2094 OC_Fbit
(OC_Count
) := Fbit
+ Posit
;
2095 OC_Lbit
(OC_Count
) := Lbit
+ Posit
;
2104 OC_Move
'Unrestricted_Access,
2105 OC_Lt
'Unrestricted_Access);
2107 Overlap_Check_Required
:= False;
2108 for J
in 1 .. OC_Count
- 1 loop
2109 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
2110 Overlap_Check_Required
:= True;
2117 -- If Overlap_Check_Required is still True, then we have to do
2118 -- the full scale overlap check, since we have at least two fields
2119 -- that do overlap, and we need to know if that is OK since they
2120 -- are in the same variant, or whether we have a definite problem
2122 if Overlap_Check_Required
then
2123 Overlap_Check2
: declare
2124 C1_Ent
, C2_Ent
: Entity_Id
;
2125 -- Entities of components being checked for overlap
2128 -- Component_List node whose Component_Items are being checked
2131 -- Component declaration for component being checked
2134 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
2136 -- Loop through all components in record. For each component check
2137 -- for overlap with any of the preceding elements on the component
2138 -- list containing the component, and also, if the component is in
2139 -- a variant, check against components outside the case structure.
2140 -- This latter test is repeated recursively up the variant tree.
2142 Main_Component_Loop
: while Present
(C1_Ent
) loop
2143 if Ekind
(C1_Ent
) /= E_Component
2144 and then Ekind
(C1_Ent
) /= E_Discriminant
2146 goto Continue_Main_Component_Loop
;
2149 -- Skip overlap check if entity has no declaration node. This
2150 -- happens with discriminants in constrained derived types.
2151 -- Probably we are missing some checks as a result, but that
2152 -- does not seem terribly serious ???
2154 if No
(Declaration_Node
(C1_Ent
)) then
2155 goto Continue_Main_Component_Loop
;
2158 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
2160 -- Loop through component lists that need checking. Check the
2161 -- current component list and all lists in variants above us.
2163 Component_List_Loop
: loop
2165 -- If derived type definition, go to full declaration
2166 -- If at outer level, check discriminants if there are any
2168 if Nkind
(Clist
) = N_Derived_Type_Definition
then
2169 Clist
:= Parent
(Clist
);
2172 -- Outer level of record definition, check discriminants
2174 if Nkind
(Clist
) = N_Full_Type_Declaration
2175 or else Nkind
(Clist
) = N_Private_Type_Declaration
2177 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
2179 First_Discriminant
(Defining_Identifier
(Clist
));
2181 while Present
(C2_Ent
) loop
2182 exit when C1_Ent
= C2_Ent
;
2183 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2184 Next_Discriminant
(C2_Ent
);
2188 -- Record extension case
2190 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
2193 -- Otherwise check one component list
2196 Citem
:= First
(Component_Items
(Clist
));
2198 while Present
(Citem
) loop
2199 if Nkind
(Citem
) = N_Component_Declaration
then
2200 C2_Ent
:= Defining_Identifier
(Citem
);
2201 exit when C1_Ent
= C2_Ent
;
2202 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2209 -- Check for variants above us (the parent of the Clist can
2210 -- be a variant, in which case its parent is a variant part,
2211 -- and the parent of the variant part is a component list
2212 -- whose components must all be checked against the current
2213 -- component for overlap.
2215 if Nkind
(Parent
(Clist
)) = N_Variant
then
2216 Clist
:= Parent
(Parent
(Parent
(Clist
)));
2218 -- Check for possible discriminant part in record, this is
2219 -- treated essentially as another level in the recursion.
2220 -- For this case we have the parent of the component list
2221 -- is the record definition, and its parent is the full
2222 -- type declaration which contains the discriminant
2225 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
2226 Clist
:= Parent
(Parent
((Clist
)));
2228 -- If neither of these two cases, we are at the top of
2232 exit Component_List_Loop
;
2234 end loop Component_List_Loop
;
2236 <<Continue_Main_Component_Loop
>>
2237 Next_Entity
(C1_Ent
);
2239 end loop Main_Component_Loop
;
2243 -- For records that have component clauses for all components, and
2244 -- whose size is less than or equal to 32, we need to know the size
2245 -- in the front end to activate possible packed array processing
2246 -- where the component type is a record.
2248 -- At this stage Hbit + 1 represents the first unused bit from all
2249 -- the component clauses processed, so if the component clauses are
2250 -- complete, then this is the length of the record.
2252 -- For records longer than System.Storage_Unit, and for those where
2253 -- not all components have component clauses, the back end determines
2254 -- the length (it may for example be appopriate to round up the size
2255 -- to some convenient boundary, based on alignment considerations etc).
2257 if Unknown_RM_Size
(Rectype
)
2258 and then Hbit
+ 1 <= 32
2260 -- Nothing to do if at least one component with no component clause
2262 Comp
:= First_Entity
(Rectype
);
2263 while Present
(Comp
) loop
2264 if Ekind
(Comp
) = E_Component
2265 or else Ekind
(Comp
) = E_Discriminant
2267 if No
(Component_Clause
(Comp
)) then
2275 -- If we fall out of loop, all components have component clauses
2276 -- and so we can set the size to the maximum value.
2278 Set_RM_Size
(Rectype
, Hbit
+ 1);
2280 end Analyze_Record_Representation_Clause
;
2282 -----------------------------
2283 -- Check_Component_Overlap --
2284 -----------------------------
2286 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
2288 if Present
(Component_Clause
(C1_Ent
))
2289 and then Present
(Component_Clause
(C2_Ent
))
2291 -- Exclude odd case where we have two tag fields in the same
2292 -- record, both at location zero. This seems a bit strange,
2293 -- but it seems to happen in some circumstances ???
2295 if Chars
(C1_Ent
) = Name_uTag
2296 and then Chars
(C2_Ent
) = Name_uTag
2301 -- Here we check if the two fields overlap
2304 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
2305 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
2306 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
2307 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
2310 if E2
<= S1
or else E1
<= S2
then
2314 Component_Name
(Component_Clause
(C2_Ent
));
2315 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
2317 Component_Name
(Component_Clause
(C1_Ent
));
2319 ("component& overlaps & #",
2320 Component_Name
(Component_Clause
(C1_Ent
)));
2324 end Check_Component_Overlap
;
2326 -----------------------------------
2327 -- Check_Constant_Address_Clause --
2328 -----------------------------------
2330 procedure Check_Constant_Address_Clause
2334 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
2335 -- Checks that the given node N represents a name whose 'Address
2336 -- is constant (in the same sense as OK_Constant_Address_Clause,
2337 -- i.e. the address value is the same at the point of declaration
2338 -- of U_Ent and at the time of elaboration of the address clause.
2340 procedure Check_Expr_Constants
(Nod
: Node_Id
);
2341 -- Checks that Nod meets the requirements for a constant address
2342 -- clause in the sense of the enclosing procedure.
2344 procedure Check_List_Constants
(Lst
: List_Id
);
2345 -- Check that all elements of list Lst meet the requirements for a
2346 -- constant address clause in the sense of the enclosing procedure.
2348 -------------------------------
2349 -- Check_At_Constant_Address --
2350 -------------------------------
2352 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
2354 if Is_Entity_Name
(Nod
) then
2355 if Present
(Address_Clause
(Entity
((Nod
)))) then
2357 ("invalid address clause for initialized object &!",
2360 ("address for& cannot" &
2361 " depend on another address clause! ('R'M 13.1(22))!",
2364 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
2365 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
2368 ("invalid address clause for initialized object &!",
2370 Error_Msg_Name_1
:= Chars
(Entity
(Nod
));
2371 Error_Msg_Name_2
:= Chars
(U_Ent
);
2373 ("\% must be defined before % ('R'M 13.1(22))!",
2377 elsif Nkind
(Nod
) = N_Selected_Component
then
2379 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
2382 if (Is_Record_Type
(T
)
2383 and then Has_Discriminants
(T
))
2386 and then Is_Record_Type
(Designated_Type
(T
))
2387 and then Has_Discriminants
(Designated_Type
(T
)))
2390 ("invalid address clause for initialized object &!",
2393 ("\address cannot depend on component" &
2394 " of discriminated record ('R'M 13.1(22))!",
2397 Check_At_Constant_Address
(Prefix
(Nod
));
2401 elsif Nkind
(Nod
) = N_Indexed_Component
then
2402 Check_At_Constant_Address
(Prefix
(Nod
));
2403 Check_List_Constants
(Expressions
(Nod
));
2406 Check_Expr_Constants
(Nod
);
2408 end Check_At_Constant_Address
;
2410 --------------------------
2411 -- Check_Expr_Constants --
2412 --------------------------
2414 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
2415 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
2416 Ent
: Entity_Id
:= Empty
;
2419 if Nkind
(Nod
) in N_Has_Etype
2420 and then Etype
(Nod
) = Any_Type
2426 when N_Empty | N_Error
=>
2429 when N_Identifier | N_Expanded_Name
=>
2430 Ent
:= Entity
(Nod
);
2432 -- We need to look at the original node if it is different
2433 -- from the node, since we may have rewritten things and
2434 -- substituted an identifier representing the rewrite.
2436 if Original_Node
(Nod
) /= Nod
then
2437 Check_Expr_Constants
(Original_Node
(Nod
));
2439 -- If the node is an object declaration without initial
2440 -- value, some code has been expanded, and the expression
2441 -- is not constant, even if the constituents might be
2442 -- acceptable, as in A'Address + offset.
2444 if Ekind
(Ent
) = E_Variable
2445 and then Nkind
(Declaration_Node
(Ent
))
2446 = N_Object_Declaration
2448 No
(Expression
(Declaration_Node
(Ent
)))
2451 ("invalid address clause for initialized object &!",
2454 -- If entity is constant, it may be the result of expanding
2455 -- a check. We must verify that its declaration appears
2456 -- before the object in question, else we also reject the
2459 elsif Ekind
(Ent
) = E_Constant
2460 and then In_Same_Source_Unit
(Ent
, U_Ent
)
2461 and then Sloc
(Ent
) > Loc_U_Ent
2464 ("invalid address clause for initialized object &!",
2471 -- Otherwise look at the identifier and see if it is OK
2473 if Ekind
(Ent
) = E_Named_Integer
2475 Ekind
(Ent
) = E_Named_Real
2482 Ekind
(Ent
) = E_Constant
2484 Ekind
(Ent
) = E_In_Parameter
2486 -- This is the case where we must have Ent defined
2487 -- before U_Ent. Clearly if they are in different
2488 -- units this requirement is met since the unit
2489 -- containing Ent is already processed.
2491 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
2494 -- Otherwise location of Ent must be before the
2495 -- location of U_Ent, that's what prior defined means.
2497 elsif Sloc
(Ent
) < Loc_U_Ent
then
2502 ("invalid address clause for initialized object &!",
2504 Error_Msg_Name_1
:= Chars
(Ent
);
2505 Error_Msg_Name_2
:= Chars
(U_Ent
);
2507 ("\% must be defined before % ('R'M 13.1(22))!",
2511 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2512 Check_Expr_Constants
(Original_Node
(Nod
));
2516 ("invalid address clause for initialized object &!",
2519 if Comes_From_Source
(Ent
) then
2520 Error_Msg_Name_1
:= Chars
(Ent
);
2522 ("\reference to variable% not allowed"
2523 & " ('R'M 13.1(22))!", Nod
);
2526 ("non-static expression not allowed"
2527 & " ('R'M 13.1(22))!", Nod
);
2531 when N_Integer_Literal
=>
2533 -- If this is a rewritten unchecked conversion, in a system
2534 -- where Address is an integer type, always use the base type
2535 -- for a literal value. This is user-friendly and prevents
2536 -- order-of-elaboration issues with instances of unchecked
2539 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2540 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2543 when N_Real_Literal |
2545 N_Character_Literal
=>
2549 Check_Expr_Constants
(Low_Bound
(Nod
));
2550 Check_Expr_Constants
(High_Bound
(Nod
));
2552 when N_Explicit_Dereference
=>
2553 Check_Expr_Constants
(Prefix
(Nod
));
2555 when N_Indexed_Component
=>
2556 Check_Expr_Constants
(Prefix
(Nod
));
2557 Check_List_Constants
(Expressions
(Nod
));
2560 Check_Expr_Constants
(Prefix
(Nod
));
2561 Check_Expr_Constants
(Discrete_Range
(Nod
));
2563 when N_Selected_Component
=>
2564 Check_Expr_Constants
(Prefix
(Nod
));
2566 when N_Attribute_Reference
=>
2568 if Attribute_Name
(Nod
) = Name_Address
2570 Attribute_Name
(Nod
) = Name_Access
2572 Attribute_Name
(Nod
) = Name_Unchecked_Access
2574 Attribute_Name
(Nod
) = Name_Unrestricted_Access
2576 Check_At_Constant_Address
(Prefix
(Nod
));
2579 Check_Expr_Constants
(Prefix
(Nod
));
2580 Check_List_Constants
(Expressions
(Nod
));
2584 Check_List_Constants
(Component_Associations
(Nod
));
2585 Check_List_Constants
(Expressions
(Nod
));
2587 when N_Component_Association
=>
2588 Check_Expr_Constants
(Expression
(Nod
));
2590 when N_Extension_Aggregate
=>
2591 Check_Expr_Constants
(Ancestor_Part
(Nod
));
2592 Check_List_Constants
(Component_Associations
(Nod
));
2593 Check_List_Constants
(Expressions
(Nod
));
2598 when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In
=>
2599 Check_Expr_Constants
(Left_Opnd
(Nod
));
2600 Check_Expr_Constants
(Right_Opnd
(Nod
));
2603 Check_Expr_Constants
(Right_Opnd
(Nod
));
2605 when N_Type_Conversion |
2606 N_Qualified_Expression |
2608 Check_Expr_Constants
(Expression
(Nod
));
2610 when N_Unchecked_Type_Conversion
=>
2611 Check_Expr_Constants
(Expression
(Nod
));
2613 -- If this is a rewritten unchecked conversion, subtypes
2614 -- in this node are those created within the instance.
2615 -- To avoid order of elaboration issues, replace them
2616 -- with their base types. Note that address clauses can
2617 -- cause order of elaboration problems because they are
2618 -- elaborated by the back-end at the point of definition,
2619 -- and may mention entities declared in between (as long
2620 -- as everything is static). It is user-friendly to allow
2621 -- unchecked conversions in this context.
2623 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2624 Set_Etype
(Expression
(Nod
),
2625 Base_Type
(Etype
(Expression
(Nod
))));
2626 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2629 when N_Function_Call
=>
2630 if not Is_Pure
(Entity
(Name
(Nod
))) then
2632 ("invalid address clause for initialized object &!",
2636 ("\function & is not pure ('R'M 13.1(22))!",
2637 Nod
, Entity
(Name
(Nod
)));
2640 Check_List_Constants
(Parameter_Associations
(Nod
));
2643 when N_Parameter_Association
=>
2644 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
2648 ("invalid address clause for initialized object &!",
2651 ("\must be constant defined before& ('R'M 13.1(22))!",
2654 end Check_Expr_Constants
;
2656 --------------------------
2657 -- Check_List_Constants --
2658 --------------------------
2660 procedure Check_List_Constants
(Lst
: List_Id
) is
2664 if Present
(Lst
) then
2665 Nod1
:= First
(Lst
);
2666 while Present
(Nod1
) loop
2667 Check_Expr_Constants
(Nod1
);
2671 end Check_List_Constants
;
2673 -- Start of processing for Check_Constant_Address_Clause
2676 Check_Expr_Constants
(Expr
);
2677 end Check_Constant_Address_Clause
;
2683 procedure Check_Size
2687 Biased
: out Boolean)
2689 UT
: constant Entity_Id
:= Underlying_Type
(T
);
2695 -- Dismiss cases for generic types or types with previous errors
2698 or else UT
= Any_Type
2699 or else Is_Generic_Type
(UT
)
2700 or else Is_Generic_Type
(Root_Type
(UT
))
2704 -- Check case of bit packed array
2706 elsif Is_Array_Type
(UT
)
2707 and then Known_Static_Component_Size
(UT
)
2708 and then Is_Bit_Packed_Array
(UT
)
2716 Asiz
:= Component_Size
(UT
);
2717 Indx
:= First_Index
(UT
);
2719 Ityp
:= Etype
(Indx
);
2721 -- If non-static bound, then we are not in the business of
2722 -- trying to check the length, and indeed an error will be
2723 -- issued elsewhere, since sizes of non-static array types
2724 -- cannot be set implicitly or explicitly.
2726 if not Is_Static_Subtype
(Ityp
) then
2730 -- Otherwise accumulate next dimension
2732 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
2733 Expr_Value
(Type_Low_Bound
(Ityp
)) +
2737 exit when No
(Indx
);
2743 Error_Msg_Uint_1
:= Asiz
;
2745 ("size for& too small, minimum allowed is ^", N
, T
);
2746 Set_Esize
(T
, Asiz
);
2747 Set_RM_Size
(T
, Asiz
);
2751 -- All other composite types are ignored
2753 elsif Is_Composite_Type
(UT
) then
2756 -- For fixed-point types, don't check minimum if type is not frozen,
2757 -- since we don't know all the characteristics of the type that can
2758 -- affect the size (e.g. a specified small) till freeze time.
2760 elsif Is_Fixed_Point_Type
(UT
)
2761 and then not Is_Frozen
(UT
)
2765 -- Cases for which a minimum check is required
2768 -- Ignore if specified size is correct for the type
2770 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
2774 -- Otherwise get minimum size
2776 M
:= UI_From_Int
(Minimum_Size
(UT
));
2780 -- Size is less than minimum size, but one possibility remains
2781 -- that we can manage with the new size if we bias the type
2783 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
2786 Error_Msg_Uint_1
:= M
;
2788 ("size for& too small, minimum allowed is ^", N
, T
);
2798 -------------------------
2799 -- Get_Alignment_Value --
2800 -------------------------
2802 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
2803 Align
: constant Uint
:= Static_Integer
(Expr
);
2806 if Align
= No_Uint
then
2809 elsif Align
<= 0 then
2810 Error_Msg_N
("alignment value must be positive", Expr
);
2814 for J
in Int
range 0 .. 64 loop
2816 M
: constant Uint
:= Uint_2
** J
;
2819 exit when M
= Align
;
2823 ("alignment value must be power of 2", Expr
);
2831 end Get_Alignment_Value
;
2837 procedure Initialize
is
2839 Unchecked_Conversions
.Init
;
2842 -------------------------
2843 -- Is_Operational_Item --
2844 -------------------------
2846 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
2848 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
2852 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
2855 return Id
= Attribute_Input
2856 or else Id
= Attribute_Output
2857 or else Id
= Attribute_Read
2858 or else Id
= Attribute_Write
2859 or else Id
= Attribute_External_Tag
;
2862 end Is_Operational_Item
;
2864 --------------------------------------
2865 -- Mark_Aliased_Address_As_Volatile --
2866 --------------------------------------
2868 procedure Mark_Aliased_Address_As_Volatile
(N
: Node_Id
) is
2869 Ent
: constant Entity_Id
:= Address_Aliased_Entity
(N
);
2872 if Present
(Ent
) then
2873 Set_Treat_As_Volatile
(Ent
);
2875 end Mark_Aliased_Address_As_Volatile
;
2881 function Minimum_Size
2883 Biased
: Boolean := False) return Nat
2885 Lo
: Uint
:= No_Uint
;
2886 Hi
: Uint
:= No_Uint
;
2887 LoR
: Ureal
:= No_Ureal
;
2888 HiR
: Ureal
:= No_Ureal
;
2889 LoSet
: Boolean := False;
2890 HiSet
: Boolean := False;
2894 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
2897 -- If bad type, return 0
2899 if T
= Any_Type
then
2902 -- For generic types, just return zero. There cannot be any legitimate
2903 -- need to know such a size, but this routine may be called with a
2904 -- generic type as part of normal processing.
2906 elsif Is_Generic_Type
(R_Typ
)
2907 or else R_Typ
= Any_Type
2911 -- Access types. Normally an access type cannot have a size smaller
2912 -- than the size of System.Address. The exception is on VMS, where
2913 -- we have short and long addresses, and it is possible for an access
2914 -- type to have a short address size (and thus be less than the size
2915 -- of System.Address itself). We simply skip the check for VMS, and
2916 -- leave the back end to do the check.
2918 elsif Is_Access_Type
(T
) then
2919 if OpenVMS_On_Target
then
2922 return System_Address_Size
;
2925 -- Floating-point types
2927 elsif Is_Floating_Point_Type
(T
) then
2928 return UI_To_Int
(Esize
(R_Typ
));
2932 elsif Is_Discrete_Type
(T
) then
2934 -- The following loop is looking for the nearest compile time
2935 -- known bounds following the ancestor subtype chain. The idea
2936 -- is to find the most restrictive known bounds information.
2940 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
2945 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
2946 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
2953 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
2954 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
2960 Ancest
:= Ancestor_Subtype
(Ancest
);
2963 Ancest
:= Base_Type
(T
);
2965 if Is_Generic_Type
(Ancest
) then
2971 -- Fixed-point types. We can't simply use Expr_Value to get the
2972 -- Corresponding_Integer_Value values of the bounds, since these
2973 -- do not get set till the type is frozen, and this routine can
2974 -- be called before the type is frozen. Similarly the test for
2975 -- bounds being static needs to include the case where we have
2976 -- unanalyzed real literals for the same reason.
2978 elsif Is_Fixed_Point_Type
(T
) then
2980 -- The following loop is looking for the nearest compile time
2981 -- known bounds following the ancestor subtype chain. The idea
2982 -- is to find the most restrictive known bounds information.
2986 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
2991 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
2992 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
2994 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
3001 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
3002 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
3004 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
3010 Ancest
:= Ancestor_Subtype
(Ancest
);
3013 Ancest
:= Base_Type
(T
);
3015 if Is_Generic_Type
(Ancest
) then
3021 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
3022 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
3024 -- No other types allowed
3027 raise Program_Error
;
3030 -- Fall through with Hi and Lo set. Deal with biased case
3032 if (Biased
and then not Is_Fixed_Point_Type
(T
))
3033 or else Has_Biased_Representation
(T
)
3039 -- Signed case. Note that we consider types like range 1 .. -1 to be
3040 -- signed for the purpose of computing the size, since the bounds
3041 -- have to be accomodated in the base type.
3043 if Lo
< 0 or else Hi
< 0 then
3047 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3048 -- Note that we accommodate the case where the bounds cross. This
3049 -- can happen either because of the way the bounds are declared
3050 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3064 -- If both bounds are positive, make sure that both are represen-
3065 -- table in the case where the bounds are crossed. This can happen
3066 -- either because of the way the bounds are declared, or because of
3067 -- the algorithm in Freeze_Fixed_Point_Type.
3073 -- S = size, (can accommodate 0 .. (2**size - 1))
3076 while Hi
>= Uint_2
** S
loop
3084 -------------------------
3085 -- New_Stream_Function --
3086 -------------------------
3088 procedure New_Stream_Function
3092 Nam
: TSS_Name_Type
)
3094 Loc
: constant Source_Ptr
:= Sloc
(N
);
3095 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3096 Subp_Id
: Entity_Id
;
3097 Subp_Decl
: Node_Id
;
3101 function Build_Spec
return Node_Id
;
3102 -- Used for declaration and renaming declaration, so that this is
3103 -- treated as a renaming_as_body.
3109 function Build_Spec
return Node_Id
is
3111 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3114 Make_Function_Specification
(Loc
,
3115 Defining_Unit_Name
=> Subp_Id
,
3116 Parameter_Specifications
=>
3118 Make_Parameter_Specification
(Loc
,
3119 Defining_Identifier
=>
3120 Make_Defining_Identifier
(Loc
, Name_S
),
3122 Make_Access_Definition
(Loc
,
3125 Designated_Type
(Etype
(F
)), Loc
)))),
3128 New_Reference_To
(Etyp
, Loc
));
3131 -- Start of processing for New_Stream_Function
3134 F
:= First_Formal
(Subp
);
3135 Etyp
:= Etype
(Subp
);
3137 if not Is_Tagged_Type
(Ent
) then
3139 Make_Subprogram_Declaration
(Loc
,
3140 Specification
=> Build_Spec
);
3141 Insert_Action
(N
, Subp_Decl
);
3145 Make_Subprogram_Renaming_Declaration
(Loc
,
3146 Specification
=> Build_Spec
,
3147 Name
=> New_Reference_To
(Subp
, Loc
));
3149 if Is_Tagged_Type
(Ent
) then
3150 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3152 Insert_Action
(N
, Subp_Decl
);
3153 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3155 end New_Stream_Function
;
3157 --------------------------
3158 -- New_Stream_Procedure --
3159 --------------------------
3161 procedure New_Stream_Procedure
3165 Nam
: TSS_Name_Type
;
3166 Out_P
: Boolean := False)
3168 Loc
: constant Source_Ptr
:= Sloc
(N
);
3169 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3170 Subp_Id
: Entity_Id
;
3171 Subp_Decl
: Node_Id
;
3175 function Build_Spec
return Node_Id
;
3176 -- Used for declaration and renaming declaration, so that this is
3177 -- treated as a renaming_as_body.
3183 function Build_Spec
return Node_Id
is
3185 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3188 Make_Procedure_Specification
(Loc
,
3189 Defining_Unit_Name
=> Subp_Id
,
3190 Parameter_Specifications
=>
3192 Make_Parameter_Specification
(Loc
,
3193 Defining_Identifier
=>
3194 Make_Defining_Identifier
(Loc
, Name_S
),
3196 Make_Access_Definition
(Loc
,
3199 Designated_Type
(Etype
(F
)), Loc
))),
3201 Make_Parameter_Specification
(Loc
,
3202 Defining_Identifier
=>
3203 Make_Defining_Identifier
(Loc
, Name_V
),
3204 Out_Present
=> Out_P
,
3206 New_Reference_To
(Etyp
, Loc
))));
3209 -- Start of processing for New_Stream_Procedure
3212 F
:= First_Formal
(Subp
);
3213 Etyp
:= Etype
(Next_Formal
(F
));
3215 if not Is_Tagged_Type
(Ent
) then
3217 Make_Subprogram_Declaration
(Loc
,
3218 Specification
=> Build_Spec
);
3219 Insert_Action
(N
, Subp_Decl
);
3223 Make_Subprogram_Renaming_Declaration
(Loc
,
3224 Specification
=> Build_Spec
,
3225 Name
=> New_Reference_To
(Subp
, Loc
));
3227 if Is_Tagged_Type
(Ent
) then
3228 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3230 Insert_Action
(N
, Subp_Decl
);
3231 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3233 end New_Stream_Procedure
;
3235 ------------------------
3236 -- Rep_Item_Too_Early --
3237 ------------------------
3239 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
3241 -- Cannot apply rep items that are not operational items
3244 if Is_Operational_Item
(N
) then
3248 and then Is_Generic_Type
(Root_Type
(T
))
3251 ("representation item not allowed for generic type", N
);
3255 -- Otherwise check for incompleted type
3257 if Is_Incomplete_Or_Private_Type
(T
)
3258 and then No
(Underlying_Type
(T
))
3261 ("representation item must be after full type declaration", N
);
3264 -- If the type has incompleted components, a representation clause is
3265 -- illegal but stream attributes and Convention pragmas are correct.
3267 elsif Has_Private_Component
(T
) then
3268 if Nkind
(N
) = N_Pragma
then
3272 ("representation item must appear after type is fully defined",
3279 end Rep_Item_Too_Early
;
3281 -----------------------
3282 -- Rep_Item_Too_Late --
3283 -----------------------
3285 function Rep_Item_Too_Late
3288 FOnly
: Boolean := False) return Boolean
3291 Parent_Type
: Entity_Id
;
3294 -- Output the too late message. Note that this is not considered a
3295 -- serious error, since the effect is simply that we ignore the
3296 -- representation clause in this case.
3302 procedure Too_Late
is
3304 Error_Msg_N
("|representation item appears too late!", N
);
3307 -- Start of processing for Rep_Item_Too_Late
3310 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3311 -- types, which may be frozen if they appear in a representation clause
3312 -- for a local type.
3315 and then not From_With_Type
(T
)
3318 S
:= First_Subtype
(T
);
3320 if Present
(Freeze_Node
(S
)) then
3322 ("?no more representation items for }!", Freeze_Node
(S
), S
);
3327 -- Check for case of non-tagged derived type whose parent either has
3328 -- primitive operations, or is a by reference type (RM 13.1(10)).
3332 and then Is_Derived_Type
(T
)
3333 and then not Is_Tagged_Type
(T
)
3335 Parent_Type
:= Etype
(Base_Type
(T
));
3337 if Has_Primitive_Operations
(Parent_Type
) then
3340 ("primitive operations already defined for&!", N
, Parent_Type
);
3343 elsif Is_By_Reference_Type
(Parent_Type
) then
3346 ("parent type & is a by reference type!", N
, Parent_Type
);
3351 -- No error, link item into head of chain of rep items for the entity
3353 Record_Rep_Item
(T
, N
);
3355 end Rep_Item_Too_Late
;
3357 -------------------------
3358 -- Same_Representation --
3359 -------------------------
3361 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
3362 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
3363 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
3366 -- A quick check, if base types are the same, then we definitely have
3367 -- the same representation, because the subtype specific representation
3368 -- attributes (Size and Alignment) do not affect representation from
3369 -- the point of view of this test.
3371 if Base_Type
(T1
) = Base_Type
(T2
) then
3374 elsif Is_Private_Type
(Base_Type
(T2
))
3375 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
3380 -- Tagged types never have differing representations
3382 if Is_Tagged_Type
(T1
) then
3386 -- Representations are definitely different if conventions differ
3388 if Convention
(T1
) /= Convention
(T2
) then
3392 -- Representations are different if component alignments differ
3394 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
3396 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
3397 and then Component_Alignment
(T1
) /= Component_Alignment
(T2
)
3402 -- For arrays, the only real issue is component size. If we know the
3403 -- component size for both arrays, and it is the same, then that's
3404 -- good enough to know we don't have a change of representation.
3406 if Is_Array_Type
(T1
) then
3407 if Known_Component_Size
(T1
)
3408 and then Known_Component_Size
(T2
)
3409 and then Component_Size
(T1
) = Component_Size
(T2
)
3415 -- Types definitely have same representation if neither has non-standard
3416 -- representation since default representations are always consistent.
3417 -- If only one has non-standard representation, and the other does not,
3418 -- then we consider that they do not have the same representation. They
3419 -- might, but there is no way of telling early enough.
3421 if Has_Non_Standard_Rep
(T1
) then
3422 if not Has_Non_Standard_Rep
(T2
) then
3426 return not Has_Non_Standard_Rep
(T2
);
3429 -- Here the two types both have non-standard representation, and we
3430 -- need to determine if they have the same non-standard representation
3432 -- For arrays, we simply need to test if the component sizes are the
3433 -- same. Pragma Pack is reflected in modified component sizes, so this
3434 -- check also deals with pragma Pack.
3436 if Is_Array_Type
(T1
) then
3437 return Component_Size
(T1
) = Component_Size
(T2
);
3439 -- Tagged types always have the same representation, because it is not
3440 -- possible to specify different representations for common fields.
3442 elsif Is_Tagged_Type
(T1
) then
3445 -- Case of record types
3447 elsif Is_Record_Type
(T1
) then
3449 -- Packed status must conform
3451 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
3454 -- Otherwise we must check components. Typ2 maybe a constrained
3455 -- subtype with fewer components, so we compare the components
3456 -- of the base types.
3459 Record_Case
: declare
3460 CD1
, CD2
: Entity_Id
;
3462 function Same_Rep
return Boolean;
3463 -- CD1 and CD2 are either components or discriminants. This
3464 -- function tests whether the two have the same representation
3470 function Same_Rep
return Boolean is
3472 if No
(Component_Clause
(CD1
)) then
3473 return No
(Component_Clause
(CD2
));
3477 Present
(Component_Clause
(CD2
))
3479 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
3481 Esize
(CD1
) = Esize
(CD2
);
3485 -- Start processing for Record_Case
3488 if Has_Discriminants
(T1
) then
3489 CD1
:= First_Discriminant
(T1
);
3490 CD2
:= First_Discriminant
(T2
);
3492 -- The number of discriminants may be different if the
3493 -- derived type has fewer (constrained by values). The
3494 -- invisible discriminants retain the representation of
3495 -- the original, so the discrepancy does not per se
3496 -- indicate a different representation.
3499 and then Present
(CD2
)
3501 if not Same_Rep
then
3504 Next_Discriminant
(CD1
);
3505 Next_Discriminant
(CD2
);
3510 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
3511 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
3513 while Present
(CD1
) loop
3514 if not Same_Rep
then
3517 Next_Component
(CD1
);
3518 Next_Component
(CD2
);
3526 -- For enumeration types, we must check each literal to see if the
3527 -- representation is the same. Note that we do not permit enumeration
3528 -- reprsentation clauses for Character and Wide_Character, so these
3529 -- cases were already dealt with.
3531 elsif Is_Enumeration_Type
(T1
) then
3533 Enumeration_Case
: declare
3537 L1
:= First_Literal
(T1
);
3538 L2
:= First_Literal
(T2
);
3540 while Present
(L1
) loop
3541 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
3551 end Enumeration_Case
;
3553 -- Any other types have the same representation for these purposes
3558 end Same_Representation
;
3560 --------------------
3561 -- Set_Enum_Esize --
3562 --------------------
3564 procedure Set_Enum_Esize
(T
: Entity_Id
) is
3572 -- Find the minimum standard size (8,16,32,64) that fits
3574 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
3575 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
3578 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
3579 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3581 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
3584 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
3587 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
3592 if Hi
< Uint_2
**08 then
3593 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3595 elsif Hi
< Uint_2
**16 then
3598 elsif Hi
< Uint_2
**32 then
3601 else pragma Assert
(Hi
< Uint_2
**63);
3606 -- That minimum is the proper size unless we have a foreign convention
3607 -- and the size required is 32 or less, in which case we bump the size
3608 -- up to 32. This is required for C and C++ and seems reasonable for
3609 -- all other foreign conventions.
3611 if Has_Foreign_Convention
(T
)
3612 and then Esize
(T
) < Standard_Integer_Size
3614 Init_Esize
(T
, Standard_Integer_Size
);
3621 -----------------------------------
3622 -- Validate_Unchecked_Conversion --
3623 -----------------------------------
3625 procedure Validate_Unchecked_Conversion
3627 Act_Unit
: Entity_Id
)
3634 -- Obtain source and target types. Note that we call Ancestor_Subtype
3635 -- here because the processing for generic instantiation always makes
3636 -- subtypes, and we want the original frozen actual types.
3638 -- If we are dealing with private types, then do the check on their
3639 -- fully declared counterparts if the full declarations have been
3640 -- encountered (they don't have to be visible, but they must exist!)
3642 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
3644 if Is_Private_Type
(Source
)
3645 and then Present
(Underlying_Type
(Source
))
3647 Source
:= Underlying_Type
(Source
);
3650 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
3652 -- If either type is generic, the instantiation happens within a
3653 -- generic unit, and there is nothing to check. The proper check
3654 -- will happen when the enclosing generic is instantiated.
3656 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
3660 if Is_Private_Type
(Target
)
3661 and then Present
(Underlying_Type
(Target
))
3663 Target
:= Underlying_Type
(Target
);
3666 -- Source may be unconstrained array, but not target
3668 if Is_Array_Type
(Target
)
3669 and then not Is_Constrained
(Target
)
3672 ("unchecked conversion to unconstrained array not allowed", N
);
3676 -- Make entry in unchecked conversion table for later processing
3677 -- by Validate_Unchecked_Conversions, which will check sizes and
3678 -- alignments (using values set by the back-end where possible).
3679 -- This is only done if the appropriate warning is active
3681 if Warn_On_Unchecked_Conversion
then
3682 Unchecked_Conversions
.Append
3683 (New_Val
=> UC_Entry
'
3688 -- If both sizes are known statically now, then back end annotation
3689 -- is not required to do a proper check but if either size is not
3690 -- known statically, then we need the annotation.
3692 if Known_Static_RM_Size (Source)
3693 and then Known_Static_RM_Size (Target)
3697 Back_Annotate_Rep_Info := True;
3701 -- If unchecked conversion to access type, and access type is
3702 -- declared in the same unit as the unchecked conversion, then
3703 -- set the No_Strict_Aliasing flag (no strict aliasing is
3704 -- implicit in this situation).
3706 if Is_Access_Type (Target) and then
3707 In_Same_Source_Unit (Target, N)
3709 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
3712 -- Generate N_Validate_Unchecked_Conversion node for back end in
3713 -- case the back end needs to perform special validation checks.
3715 -- Shouldn't this be in exp_ch13, since the check only gets done
3716 -- if we have full expansion and the back end is called ???
3719 Make_Validate_Unchecked_Conversion (Sloc (N));
3720 Set_Source_Type (Vnode, Source);
3721 Set_Target_Type (Vnode, Target);
3723 -- If the unchecked conversion node is in a list, just insert before
3724 -- it. If not we have some strange case, not worth bothering about.
3726 if Is_List_Member (N) then
3727 Insert_After (N, Vnode);
3729 end Validate_Unchecked_Conversion;
3731 ------------------------------------
3732 -- Validate_Unchecked_Conversions --
3733 ------------------------------------
3735 procedure Validate_Unchecked_Conversions is
3737 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
3739 T : UC_Entry renames Unchecked_Conversions.Table (N);
3741 Enode : constant Node_Id := T.Enode;
3742 Source : constant Entity_Id := T.Source;
3743 Target : constant Entity_Id := T.Target;
3749 -- This validation check, which warns if we have unequal sizes
3750 -- for unchecked conversion, and thus potentially implementation
3751 -- dependent semantics, is one of the few occasions on which we
3752 -- use the official RM size instead of Esize. See description
3753 -- in Einfo "Handling of Type'Size Values" for details.
3755 if Serious_Errors_Detected = 0
3756 and then Known_Static_RM_Size (Source)
3757 and then Known_Static_RM_Size (Target)
3759 Source_Siz := RM_Size (Source);
3760 Target_Siz := RM_Size (Target);
3762 if Source_Siz /= Target_Siz then
3764 ("types for unchecked conversion have different sizes?",
3767 if All_Errors_Mode then
3768 Error_Msg_Name_1 := Chars (Source);
3769 Error_Msg_Uint_1 := Source_Siz;
3770 Error_Msg_Name_2 := Chars (Target);
3771 Error_Msg_Uint_2 := Target_Siz;
3773 ("\size of % is ^, size of % is ^?", Enode);
3775 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
3777 if Is_Discrete_Type (Source)
3778 and then Is_Discrete_Type (Target)
3780 if Source_Siz > Target_Siz then
3782 ("\^ high order bits of source will be ignored?",
3785 elsif Is_Unsigned_Type (Source) then
3787 ("\source will be extended with ^ high order " &
3788 "zero bits?", Enode);
3792 ("\source will be extended with ^ high order " &
3797 elsif Source_Siz < Target_Siz then
3798 if Is_Discrete_Type (Target) then
3799 if Bytes_Big_Endian then
3801 ("\target value will include ^ undefined " &
3806 ("\target value will include ^ undefined " &
3813 ("\^ trailing bits of target value will be " &
3814 "undefined?", Enode);
3817 else pragma Assert (Source_Siz > Target_Siz);
3819 ("\^ trailing bits of source will be ignored?",
3826 -- If both types are access types, we need to check the alignment.
3827 -- If the alignment of both is specified, we can do it here.
3829 if Serious_Errors_Detected = 0
3830 and then Ekind (Source) in Access_Kind
3831 and then Ekind (Target) in Access_Kind
3832 and then Target_Strict_Alignment
3833 and then Present (Designated_Type (Source))
3834 and then Present (Designated_Type (Target))
3837 D_Source : constant Entity_Id := Designated_Type (Source);
3838 D_Target : constant Entity_Id := Designated_Type (Target);
3841 if Known_Alignment (D_Source)
3842 and then Known_Alignment (D_Target)
3845 Source_Align : constant Uint := Alignment (D_Source);
3846 Target_Align : constant Uint := Alignment (D_Target);
3849 if Source_Align < Target_Align
3850 and then not Is_Tagged_Type (D_Source)
3852 Error_Msg_Uint_1 := Target_Align;
3853 Error_Msg_Uint_2 := Source_Align;
3854 Error_Msg_Node_2 := D_Source;
3856 ("alignment of & (^) is stricter than " &
3857 "alignment of & (^)?", Enode, D_Target);
3859 if All_Errors_Mode then
3861 ("\resulting access value may have invalid " &
3862 "alignment?", Enode);
3871 end Validate_Unchecked_Conversions;