1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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
);
984 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
986 ("size for primitive object must be a power of 2"
987 & " in the range ^-^", N
);
991 Set_Esize
(U_Ent
, Size
);
994 Set_Has_Size_Clause
(U_Ent
);
1002 -- Small attribute definition clause
1004 when Attribute_Small
=> Small
: declare
1005 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
1009 Analyze_And_Resolve
(Expr
, Any_Real
);
1011 if Etype
(Expr
) = Any_Type
then
1014 elsif not Is_Static_Expression
(Expr
) then
1015 Flag_Non_Static_Expr
1016 ("small requires static expression!", Expr
);
1020 Small
:= Expr_Value_R
(Expr
);
1022 if Small
<= Ureal_0
then
1023 Error_Msg_N
("small value must be greater than zero", Expr
);
1029 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
1031 ("small requires an ordinary fixed point type", Nam
);
1033 elsif Has_Small_Clause
(U_Ent
) then
1034 Error_Msg_N
("small already given for &", Nam
);
1036 elsif Small
> Delta_Value
(U_Ent
) then
1038 ("small value must not be greater then delta value", Nam
);
1041 Set_Small_Value
(U_Ent
, Small
);
1042 Set_Small_Value
(Implicit_Base
, Small
);
1043 Set_Has_Small_Clause
(U_Ent
);
1044 Set_Has_Small_Clause
(Implicit_Base
);
1045 Set_Has_Non_Standard_Rep
(Implicit_Base
);
1053 -- Storage_Size attribute definition clause
1055 when Attribute_Storage_Size
=> Storage_Size
: declare
1056 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
1060 if Is_Task_Type
(U_Ent
) then
1061 Check_Restriction
(No_Obsolescent_Features
, N
);
1063 if Warn_On_Obsolescent_Feature
then
1065 ("storage size clause for task is an " &
1066 "obsolescent feature ('R'M 'J.9)?", N
);
1068 ("\use Storage_Size pragma instead?", N
);
1074 if not Is_Access_Type
(U_Ent
)
1075 and then Ekind
(U_Ent
) /= E_Task_Type
1077 Error_Msg_N
("storage size cannot be given for &", Nam
);
1079 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
1081 ("storage size cannot be given for a derived access type",
1084 elsif Has_Storage_Size_Clause
(Btype
) then
1085 Error_Msg_N
("storage size already given for &", Nam
);
1088 Analyze_And_Resolve
(Expr
, Any_Integer
);
1090 if Is_Access_Type
(U_Ent
) then
1092 if Present
(Associated_Storage_Pool
(U_Ent
)) then
1093 Error_Msg_N
("storage pool already given for &", Nam
);
1097 if Compile_Time_Known_Value
(Expr
)
1098 and then Expr_Value
(Expr
) = 0
1100 Set_No_Pool_Assigned
(Btype
);
1103 else -- Is_Task_Type (U_Ent)
1104 Sprag
:= Get_Rep_Pragma
(Btype
, Name_Storage_Size
);
1106 if Present
(Sprag
) then
1107 Error_Msg_Sloc
:= Sloc
(Sprag
);
1109 ("Storage_Size already specified#", Nam
);
1114 Set_Has_Storage_Size_Clause
(Btype
);
1122 -- Storage_Pool attribute definition clause
1124 when Attribute_Storage_Pool
=> Storage_Pool
: declare
1129 if Ekind
(U_Ent
) /= E_Access_Type
1130 and then Ekind
(U_Ent
) /= E_General_Access_Type
1133 "storage pool can only be given for access types", Nam
);
1136 elsif Is_Derived_Type
(U_Ent
) then
1138 ("storage pool cannot be given for a derived access type",
1141 elsif Has_Storage_Size_Clause
(U_Ent
) then
1142 Error_Msg_N
("storage size already given for &", Nam
);
1145 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
1146 Error_Msg_N
("storage pool already given for &", Nam
);
1151 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
1153 if Nkind
(Expr
) = N_Type_Conversion
then
1154 T
:= Etype
(Expression
(Expr
));
1159 -- The Stack_Bounded_Pool is used internally for implementing
1160 -- access types with a Storage_Size. Since it only work
1161 -- properly when used on one specific type, we need to check
1162 -- that it is not highjacked improperly:
1163 -- type T is access Integer;
1164 -- for T'Storage_Size use n;
1165 -- type Q is access Float;
1166 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
1168 if Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
) then
1169 Error_Msg_N
("non-sharable internal Pool", Expr
);
1173 -- If the argument is a name that is not an entity name, then
1174 -- we construct a renaming operation to define an entity of
1175 -- type storage pool.
1177 if not Is_Entity_Name
(Expr
)
1178 and then Is_Object_Reference
(Expr
)
1181 Make_Defining_Identifier
(Loc
,
1182 Chars
=> New_Internal_Name
('P'));
1185 Rnode
: constant Node_Id
:=
1186 Make_Object_Renaming_Declaration
(Loc
,
1187 Defining_Identifier
=> Pool
,
1189 New_Occurrence_Of
(Etype
(Expr
), Loc
),
1193 Insert_Before
(N
, Rnode
);
1195 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1198 elsif Is_Entity_Name
(Expr
) then
1199 Pool
:= Entity
(Expr
);
1201 -- If pool is a renamed object, get original one. This can
1202 -- happen with an explicit renaming, and within instances.
1204 while Present
(Renamed_Object
(Pool
))
1205 and then Is_Entity_Name
(Renamed_Object
(Pool
))
1207 Pool
:= Entity
(Renamed_Object
(Pool
));
1210 if Present
(Renamed_Object
(Pool
))
1211 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
1212 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
1214 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
1217 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1219 elsif Nkind
(Expr
) = N_Type_Conversion
1220 and then Is_Entity_Name
(Expression
(Expr
))
1221 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
1223 Pool
:= Entity
(Expression
(Expr
));
1224 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1227 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
1236 when Attribute_Stream_Size
=> Stream_Size
: declare
1237 Size
: constant Uint
:= Static_Integer
(Expr
);
1240 if Has_Stream_Size_Clause
(U_Ent
) then
1241 Error_Msg_N
("Stream_Size already given for &", Nam
);
1243 elsif Is_Elementary_Type
(U_Ent
) then
1244 if Size
/= System_Storage_Unit
1246 Size
/= System_Storage_Unit
* 2
1248 Size
/= System_Storage_Unit
* 4
1250 Size
/= System_Storage_Unit
* 8
1252 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
1254 ("stream size for elementary type must be a"
1255 & " power of 2 and at least ^", N
);
1257 elsif RM_Size
(U_Ent
) > Size
then
1258 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
1260 ("stream size for elementary type must be a"
1261 & " power of 2 and at least ^", N
);
1264 Set_Has_Stream_Size_Clause
(U_Ent
);
1267 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
1275 -- Value_Size attribute definition clause
1277 when Attribute_Value_Size
=> Value_Size
: declare
1278 Size
: constant Uint
:= Static_Integer
(Expr
);
1282 if not Is_Type
(U_Ent
) then
1283 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
1286 (Get_Attribute_Definition_Clause
1287 (U_Ent
, Attribute_Value_Size
))
1289 Error_Msg_N
("Value_Size already given for &", Nam
);
1292 if Is_Elementary_Type
(U_Ent
) then
1293 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
1294 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1297 Set_RM_Size
(U_Ent
, Size
);
1305 when Attribute_Write
=>
1306 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
1307 Set_Has_Specified_Stream_Write
(Ent
);
1309 -- All other attributes cannot be set
1313 ("attribute& cannot be set with definition clause", N
);
1316 -- The test for the type being frozen must be performed after
1317 -- any expression the clause has been analyzed since the expression
1318 -- itself might cause freezing that makes the clause illegal.
1320 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
1323 end Analyze_Attribute_Definition_Clause
;
1325 ----------------------------
1326 -- Analyze_Code_Statement --
1327 ----------------------------
1329 procedure Analyze_Code_Statement
(N
: Node_Id
) is
1330 HSS
: constant Node_Id
:= Parent
(N
);
1331 SBody
: constant Node_Id
:= Parent
(HSS
);
1332 Subp
: constant Entity_Id
:= Current_Scope
;
1339 -- Analyze and check we get right type, note that this implements the
1340 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1341 -- is the only way that Asm_Insn could possibly be visible.
1343 Analyze_And_Resolve
(Expression
(N
));
1345 if Etype
(Expression
(N
)) = Any_Type
then
1347 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
1348 Error_Msg_N
("incorrect type for code statement", N
);
1352 -- Make sure we appear in the handled statement sequence of a
1353 -- subprogram (RM 13.8(3)).
1355 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
1356 or else Nkind
(SBody
) /= N_Subprogram_Body
1359 ("code statement can only appear in body of subprogram", N
);
1363 -- Do remaining checks (RM 13.8(3)) if not already done
1365 if not Is_Machine_Code_Subprogram
(Subp
) then
1366 Set_Is_Machine_Code_Subprogram
(Subp
);
1368 -- No exception handlers allowed
1370 if Present
(Exception_Handlers
(HSS
)) then
1372 ("exception handlers not permitted in machine code subprogram",
1373 First
(Exception_Handlers
(HSS
)));
1376 -- No declarations other than use clauses and pragmas (we allow
1377 -- certain internally generated declarations as well).
1379 Decl
:= First
(Declarations
(SBody
));
1380 while Present
(Decl
) loop
1381 DeclO
:= Original_Node
(Decl
);
1382 if Comes_From_Source
(DeclO
)
1383 and then Nkind
(DeclO
) /= N_Pragma
1384 and then Nkind
(DeclO
) /= N_Use_Package_Clause
1385 and then Nkind
(DeclO
) /= N_Use_Type_Clause
1386 and then Nkind
(DeclO
) /= N_Implicit_Label_Declaration
1389 ("this declaration not allowed in machine code subprogram",
1396 -- No statements other than code statements, pragmas, and labels.
1397 -- Again we allow certain internally generated statements.
1399 Stmt
:= First
(Statements
(HSS
));
1400 while Present
(Stmt
) loop
1401 StmtO
:= Original_Node
(Stmt
);
1402 if Comes_From_Source
(StmtO
)
1403 and then Nkind
(StmtO
) /= N_Pragma
1404 and then Nkind
(StmtO
) /= N_Label
1405 and then Nkind
(StmtO
) /= N_Code_Statement
1408 ("this statement is not allowed in machine code subprogram",
1415 end Analyze_Code_Statement
;
1417 -----------------------------------------------
1418 -- Analyze_Enumeration_Representation_Clause --
1419 -----------------------------------------------
1421 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
1422 Ident
: constant Node_Id
:= Identifier
(N
);
1423 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
1424 Enumtype
: Entity_Id
;
1430 Err
: Boolean := False;
1432 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
1433 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
1438 -- First some basic error checks
1441 Enumtype
:= Entity
(Ident
);
1443 if Enumtype
= Any_Type
1444 or else Rep_Item_Too_Early
(Enumtype
, N
)
1448 Enumtype
:= Underlying_Type
(Enumtype
);
1451 if not Is_Enumeration_Type
(Enumtype
) then
1453 ("enumeration type required, found}",
1454 Ident
, First_Subtype
(Enumtype
));
1458 -- Ignore rep clause on generic actual type. This will already have
1459 -- been flagged on the template as an error, and this is the safest
1460 -- way to ensure we don't get a junk cascaded message in the instance.
1462 if Is_Generic_Actual_Type
(Enumtype
) then
1465 -- Type must be in current scope
1467 elsif Scope
(Enumtype
) /= Current_Scope
then
1468 Error_Msg_N
("type must be declared in this scope", Ident
);
1471 -- Type must be a first subtype
1473 elsif not Is_First_Subtype
(Enumtype
) then
1474 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
1477 -- Ignore duplicate rep clause
1479 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
1480 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
1483 -- Don't allow rep clause for standard [wide_[wide_]]character
1485 elsif Root_Type
(Enumtype
) = Standard_Character
1486 or else Root_Type
(Enumtype
) = Standard_Wide_Character
1487 or else Root_Type
(Enumtype
) = Standard_Wide_Wide_Character
1489 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
1492 -- Check that the expression is a proper aggregate (no parentheses)
1494 elsif Paren_Count
(Aggr
) /= 0 then
1496 ("extra parentheses surrounding aggregate not allowed",
1500 -- All tests passed, so set rep clause in place
1503 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
1504 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
1507 -- Now we process the aggregate. Note that we don't use the normal
1508 -- aggregate code for this purpose, because we don't want any of the
1509 -- normal expansion activities, and a number of special semantic
1510 -- rules apply (including the component type being any integer type)
1512 Elit
:= First_Literal
(Enumtype
);
1514 -- First the positional entries if any
1516 if Present
(Expressions
(Aggr
)) then
1517 Expr
:= First
(Expressions
(Aggr
));
1518 while Present
(Expr
) loop
1520 Error_Msg_N
("too many entries in aggregate", Expr
);
1524 Val
:= Static_Integer
(Expr
);
1526 -- Err signals that we found some incorrect entries processing
1527 -- the list. The final checks for completeness and ordering are
1528 -- skipped in this case.
1530 if Val
= No_Uint
then
1532 elsif Val
< Lo
or else Hi
< Val
then
1533 Error_Msg_N
("value outside permitted range", Expr
);
1537 Set_Enumeration_Rep
(Elit
, Val
);
1538 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
1544 -- Now process the named entries if present
1546 if Present
(Component_Associations
(Aggr
)) then
1547 Assoc
:= First
(Component_Associations
(Aggr
));
1548 while Present
(Assoc
) loop
1549 Choice
:= First
(Choices
(Assoc
));
1551 if Present
(Next
(Choice
)) then
1553 ("multiple choice not allowed here", Next
(Choice
));
1557 if Nkind
(Choice
) = N_Others_Choice
then
1558 Error_Msg_N
("others choice not allowed here", Choice
);
1561 elsif Nkind
(Choice
) = N_Range
then
1562 -- ??? should allow zero/one element range here
1563 Error_Msg_N
("range not allowed here", Choice
);
1567 Analyze_And_Resolve
(Choice
, Enumtype
);
1569 if Is_Entity_Name
(Choice
)
1570 and then Is_Type
(Entity
(Choice
))
1572 Error_Msg_N
("subtype name not allowed here", Choice
);
1574 -- ??? should allow static subtype with zero/one entry
1576 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
1577 if not Is_Static_Expression
(Choice
) then
1578 Flag_Non_Static_Expr
1579 ("non-static expression used for choice!", Choice
);
1583 Elit
:= Expr_Value_E
(Choice
);
1585 if Present
(Enumeration_Rep_Expr
(Elit
)) then
1586 Error_Msg_Sloc
:= Sloc
(Enumeration_Rep_Expr
(Elit
));
1588 ("representation for& previously given#",
1593 Set_Enumeration_Rep_Expr
(Elit
, Choice
);
1595 Expr
:= Expression
(Assoc
);
1596 Val
:= Static_Integer
(Expr
);
1598 if Val
= No_Uint
then
1601 elsif Val
< Lo
or else Hi
< Val
then
1602 Error_Msg_N
("value outside permitted range", Expr
);
1606 Set_Enumeration_Rep
(Elit
, Val
);
1615 -- Aggregate is fully processed. Now we check that a full set of
1616 -- representations was given, and that they are in range and in order.
1617 -- These checks are only done if no other errors occurred.
1623 Elit
:= First_Literal
(Enumtype
);
1624 while Present
(Elit
) loop
1625 if No
(Enumeration_Rep_Expr
(Elit
)) then
1626 Error_Msg_NE
("missing representation for&!", N
, Elit
);
1629 Val
:= Enumeration_Rep
(Elit
);
1631 if Min
= No_Uint
then
1635 if Val
/= No_Uint
then
1636 if Max
/= No_Uint
and then Val
<= Max
then
1638 ("enumeration value for& not ordered!",
1639 Enumeration_Rep_Expr
(Elit
), Elit
);
1645 -- If there is at least one literal whose representation
1646 -- is not equal to the Pos value, then note that this
1647 -- enumeration type has a non-standard representation.
1649 if Val
/= Enumeration_Pos
(Elit
) then
1650 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
1657 -- Now set proper size information
1660 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
1663 if Has_Size_Clause
(Enumtype
) then
1664 if Esize
(Enumtype
) >= Minsize
then
1669 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
1671 if Esize
(Enumtype
) < Minsize
then
1672 Error_Msg_N
("previously given size is too small", N
);
1675 Set_Has_Biased_Representation
(Enumtype
);
1680 Set_RM_Size
(Enumtype
, Minsize
);
1681 Set_Enum_Esize
(Enumtype
);
1684 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
1685 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
1686 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
1690 -- We repeat the too late test in case it froze itself!
1692 if Rep_Item_Too_Late
(Enumtype
, N
) then
1695 end Analyze_Enumeration_Representation_Clause
;
1697 ----------------------------
1698 -- Analyze_Free_Statement --
1699 ----------------------------
1701 procedure Analyze_Free_Statement
(N
: Node_Id
) is
1703 Analyze
(Expression
(N
));
1704 end Analyze_Free_Statement
;
1706 ------------------------------------------
1707 -- Analyze_Record_Representation_Clause --
1708 ------------------------------------------
1710 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
1711 Loc
: constant Source_Ptr
:= Sloc
(N
);
1712 Ident
: constant Node_Id
:= Identifier
(N
);
1713 Rectype
: Entity_Id
;
1719 Hbit
: Uint
:= Uint_0
;
1724 Max_Bit_So_Far
: Uint
;
1725 -- Records the maximum bit position so far. If all field positions
1726 -- are monotonically increasing, then we can skip the circuit for
1727 -- checking for overlap, since no overlap is possible.
1729 Overlap_Check_Required
: Boolean;
1730 -- Used to keep track of whether or not an overlap check is required
1732 Ccount
: Natural := 0;
1733 -- Number of component clauses in record rep clause
1735 CR_Pragma
: Node_Id
:= Empty
;
1736 -- Points to N_Pragma node if Complete_Representation pragma present
1740 Rectype
:= Entity
(Ident
);
1742 if Rectype
= Any_Type
1743 or else Rep_Item_Too_Early
(Rectype
, N
)
1747 Rectype
:= Underlying_Type
(Rectype
);
1750 -- First some basic error checks
1752 if not Is_Record_Type
(Rectype
) then
1754 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
1757 elsif Is_Unchecked_Union
(Rectype
) then
1759 ("record rep clause not allowed for Unchecked_Union", N
);
1761 elsif Scope
(Rectype
) /= Current_Scope
then
1762 Error_Msg_N
("type must be declared in this scope", N
);
1765 elsif not Is_First_Subtype
(Rectype
) then
1766 Error_Msg_N
("cannot give record rep clause for subtype", N
);
1769 elsif Has_Record_Rep_Clause
(Rectype
) then
1770 Error_Msg_N
("duplicate record rep clause ignored", N
);
1773 elsif Rep_Item_Too_Late
(Rectype
, N
) then
1777 if Present
(Mod_Clause
(N
)) then
1779 Loc
: constant Source_Ptr
:= Sloc
(N
);
1780 M
: constant Node_Id
:= Mod_Clause
(N
);
1781 P
: constant List_Id
:= Pragmas_Before
(M
);
1785 pragma Warnings
(Off
, Mod_Val
);
1788 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
1790 if Warn_On_Obsolescent_Feature
then
1792 ("mod clause is an obsolescent feature ('R'M 'J.8)?", N
);
1794 ("\use alignment attribute definition clause instead?", N
);
1801 -- In ASIS_Mode mode, expansion is disabled, but we must
1802 -- convert the Mod clause into an alignment clause anyway, so
1803 -- that the back-end can compute and back-annotate properly the
1804 -- size and alignment of types that may include this record.
1806 if Operating_Mode
= Check_Semantics
1810 Make_Attribute_Definition_Clause
(Loc
,
1811 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
1812 Chars
=> Name_Alignment
,
1813 Expression
=> Relocate_Node
(Expression
(M
)));
1815 Set_From_At_Mod
(AtM_Nod
);
1816 Insert_After
(N
, AtM_Nod
);
1817 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
1818 Set_Mod_Clause
(N
, Empty
);
1821 -- Get the alignment value to perform error checking
1823 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
1829 -- Clear any existing component clauses for the type (this happens
1830 -- with derived types, where we are now overriding the original)
1832 Fent
:= First_Entity
(Rectype
);
1835 while Present
(Comp
) loop
1836 if Ekind
(Comp
) = E_Component
1837 or else Ekind
(Comp
) = E_Discriminant
1839 Set_Component_Clause
(Comp
, Empty
);
1845 -- All done if no component clauses
1847 CC
:= First
(Component_Clauses
(N
));
1853 -- If a tag is present, then create a component clause that places
1854 -- it at the start of the record (otherwise gigi may place it after
1855 -- other fields that have rep clauses).
1857 if Nkind
(Fent
) = N_Defining_Identifier
1858 and then Chars
(Fent
) = Name_uTag
1860 Set_Component_Bit_Offset
(Fent
, Uint_0
);
1861 Set_Normalized_Position
(Fent
, Uint_0
);
1862 Set_Normalized_First_Bit
(Fent
, Uint_0
);
1863 Set_Normalized_Position_Max
(Fent
, Uint_0
);
1864 Init_Esize
(Fent
, System_Address_Size
);
1866 Set_Component_Clause
(Fent
,
1867 Make_Component_Clause
(Loc
,
1869 Make_Identifier
(Loc
,
1870 Chars
=> Name_uTag
),
1873 Make_Integer_Literal
(Loc
,
1877 Make_Integer_Literal
(Loc
,
1881 Make_Integer_Literal
(Loc
,
1882 UI_From_Int
(System_Address_Size
))));
1884 Ccount
:= Ccount
+ 1;
1887 -- A representation like this applies to the base type
1889 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
1890 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
1891 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
1893 Max_Bit_So_Far
:= Uint_Minus_1
;
1894 Overlap_Check_Required
:= False;
1896 -- Process the component clauses
1898 while Present
(CC
) loop
1902 if Nkind
(CC
) = N_Pragma
then
1905 -- The only pragma of interest is Complete_Representation
1907 if Chars
(CC
) = Name_Complete_Representation
then
1911 -- Processing for real component clause
1914 Ccount
:= Ccount
+ 1;
1915 Posit
:= Static_Integer
(Position
(CC
));
1916 Fbit
:= Static_Integer
(First_Bit
(CC
));
1917 Lbit
:= Static_Integer
(Last_Bit
(CC
));
1920 and then Fbit
/= No_Uint
1921 and then Lbit
/= No_Uint
1925 ("position cannot be negative", Position
(CC
));
1929 ("first bit cannot be negative", First_Bit
(CC
));
1931 -- Values look OK, so find the corresponding record component
1932 -- Even though the syntax allows an attribute reference for
1933 -- implementation-defined components, GNAT does not allow the
1934 -- tag to get an explicit position.
1936 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
1937 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
1938 Error_Msg_N
("position of tag cannot be specified", CC
);
1940 Error_Msg_N
("illegal component name", CC
);
1944 Comp
:= First_Entity
(Rectype
);
1945 while Present
(Comp
) loop
1946 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
1952 -- Maybe component of base type that is absent from
1953 -- statically constrained first subtype.
1955 Comp
:= First_Entity
(Base_Type
(Rectype
));
1956 while Present
(Comp
) loop
1957 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
1964 ("component clause is for non-existent field", CC
);
1966 elsif Present
(Component_Clause
(Comp
)) then
1967 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
1969 ("component clause previously given#", CC
);
1972 -- Update Fbit and Lbit to the actual bit number
1974 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
1975 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
1977 if Fbit
<= Max_Bit_So_Far
then
1978 Overlap_Check_Required
:= True;
1980 Max_Bit_So_Far
:= Lbit
;
1983 if Has_Size_Clause
(Rectype
)
1984 and then Esize
(Rectype
) <= Lbit
1987 ("bit number out of range of specified size",
1990 Set_Component_Clause
(Comp
, CC
);
1991 Set_Component_Bit_Offset
(Comp
, Fbit
);
1992 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
1993 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
1994 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
1996 Set_Normalized_Position_Max
1997 (Fent
, Normalized_Position
(Fent
));
1999 if Is_Tagged_Type
(Rectype
)
2000 and then Fbit
< System_Address_Size
2003 ("component overlaps tag field of&",
2007 -- This information is also set in the corresponding
2008 -- component of the base type, found by accessing the
2009 -- Original_Record_Component link if it is present.
2011 Ocomp
:= Original_Record_Component
(Comp
);
2018 (Component_Name
(CC
),
2023 Set_Has_Biased_Representation
(Comp
, Biased
);
2025 if Present
(Ocomp
) then
2026 Set_Component_Clause
(Ocomp
, CC
);
2027 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
2028 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
2029 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
2030 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
2032 Set_Normalized_Position_Max
2033 (Ocomp
, Normalized_Position
(Ocomp
));
2035 Set_Has_Biased_Representation
2036 (Ocomp
, Has_Biased_Representation
(Comp
));
2039 if Esize
(Comp
) < 0 then
2040 Error_Msg_N
("component size is negative", CC
);
2051 -- Now that we have processed all the component clauses, check for
2052 -- overlap. We have to leave this till last, since the components
2053 -- can appear in any arbitrary order in the representation clause.
2055 -- We do not need this check if all specified ranges were monotonic,
2056 -- as recorded by Overlap_Check_Required being False at this stage.
2058 -- This first section checks if there are any overlapping entries
2059 -- at all. It does this by sorting all entries and then seeing if
2060 -- there are any overlaps. If there are none, then that is decisive,
2061 -- but if there are overlaps, they may still be OK (they may result
2062 -- from fields in different variants).
2064 if Overlap_Check_Required
then
2065 Overlap_Check1
: declare
2067 OC_Fbit
: array (0 .. Ccount
) of Uint
;
2068 -- First-bit values for component clauses, the value is the
2069 -- offset of the first bit of the field from start of record.
2070 -- The zero entry is for use in sorting.
2072 OC_Lbit
: array (0 .. Ccount
) of Uint
;
2073 -- Last-bit values for component clauses, the value is the
2074 -- offset of the last bit of the field from start of record.
2075 -- The zero entry is for use in sorting.
2077 OC_Count
: Natural := 0;
2078 -- Count of entries in OC_Fbit and OC_Lbit
2080 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
2081 -- Compare routine for Sort (See GNAT.Heap_Sort_A)
2083 procedure OC_Move
(From
: Natural; To
: Natural);
2084 -- Move routine for Sort (see GNAT.Heap_Sort_A)
2086 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
2088 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
2091 procedure OC_Move
(From
: Natural; To
: Natural) is
2093 OC_Fbit
(To
) := OC_Fbit
(From
);
2094 OC_Lbit
(To
) := OC_Lbit
(From
);
2098 CC
:= First
(Component_Clauses
(N
));
2099 while Present
(CC
) loop
2100 if Nkind
(CC
) /= N_Pragma
then
2101 Posit
:= Static_Integer
(Position
(CC
));
2102 Fbit
:= Static_Integer
(First_Bit
(CC
));
2103 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2106 and then Fbit
/= No_Uint
2107 and then Lbit
/= No_Uint
2109 OC_Count
:= OC_Count
+ 1;
2110 Posit
:= Posit
* SSU
;
2111 OC_Fbit
(OC_Count
) := Fbit
+ Posit
;
2112 OC_Lbit
(OC_Count
) := Lbit
+ Posit
;
2121 OC_Move
'Unrestricted_Access,
2122 OC_Lt
'Unrestricted_Access);
2124 Overlap_Check_Required
:= False;
2125 for J
in 1 .. OC_Count
- 1 loop
2126 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
2127 Overlap_Check_Required
:= True;
2134 -- If Overlap_Check_Required is still True, then we have to do
2135 -- the full scale overlap check, since we have at least two fields
2136 -- that do overlap, and we need to know if that is OK since they
2137 -- are in the same variant, or whether we have a definite problem
2139 if Overlap_Check_Required
then
2140 Overlap_Check2
: declare
2141 C1_Ent
, C2_Ent
: Entity_Id
;
2142 -- Entities of components being checked for overlap
2145 -- Component_List node whose Component_Items are being checked
2148 -- Component declaration for component being checked
2151 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
2153 -- Loop through all components in record. For each component check
2154 -- for overlap with any of the preceding elements on the component
2155 -- list containing the component, and also, if the component is in
2156 -- a variant, check against components outside the case structure.
2157 -- This latter test is repeated recursively up the variant tree.
2159 Main_Component_Loop
: while Present
(C1_Ent
) loop
2160 if Ekind
(C1_Ent
) /= E_Component
2161 and then Ekind
(C1_Ent
) /= E_Discriminant
2163 goto Continue_Main_Component_Loop
;
2166 -- Skip overlap check if entity has no declaration node. This
2167 -- happens with discriminants in constrained derived types.
2168 -- Probably we are missing some checks as a result, but that
2169 -- does not seem terribly serious ???
2171 if No
(Declaration_Node
(C1_Ent
)) then
2172 goto Continue_Main_Component_Loop
;
2175 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
2177 -- Loop through component lists that need checking. Check the
2178 -- current component list and all lists in variants above us.
2180 Component_List_Loop
: loop
2182 -- If derived type definition, go to full declaration
2183 -- If at outer level, check discriminants if there are any
2185 if Nkind
(Clist
) = N_Derived_Type_Definition
then
2186 Clist
:= Parent
(Clist
);
2189 -- Outer level of record definition, check discriminants
2191 if Nkind
(Clist
) = N_Full_Type_Declaration
2192 or else Nkind
(Clist
) = N_Private_Type_Declaration
2194 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
2196 First_Discriminant
(Defining_Identifier
(Clist
));
2198 while Present
(C2_Ent
) loop
2199 exit when C1_Ent
= C2_Ent
;
2200 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2201 Next_Discriminant
(C2_Ent
);
2205 -- Record extension case
2207 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
2210 -- Otherwise check one component list
2213 Citem
:= First
(Component_Items
(Clist
));
2215 while Present
(Citem
) loop
2216 if Nkind
(Citem
) = N_Component_Declaration
then
2217 C2_Ent
:= Defining_Identifier
(Citem
);
2218 exit when C1_Ent
= C2_Ent
;
2219 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2226 -- Check for variants above us (the parent of the Clist can
2227 -- be a variant, in which case its parent is a variant part,
2228 -- and the parent of the variant part is a component list
2229 -- whose components must all be checked against the current
2230 -- component for overlap.
2232 if Nkind
(Parent
(Clist
)) = N_Variant
then
2233 Clist
:= Parent
(Parent
(Parent
(Clist
)));
2235 -- Check for possible discriminant part in record, this is
2236 -- treated essentially as another level in the recursion.
2237 -- For this case we have the parent of the component list
2238 -- is the record definition, and its parent is the full
2239 -- type declaration which contains the discriminant
2242 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
2243 Clist
:= Parent
(Parent
((Clist
)));
2245 -- If neither of these two cases, we are at the top of
2249 exit Component_List_Loop
;
2251 end loop Component_List_Loop
;
2253 <<Continue_Main_Component_Loop
>>
2254 Next_Entity
(C1_Ent
);
2256 end loop Main_Component_Loop
;
2260 -- For records that have component clauses for all components, and
2261 -- whose size is less than or equal to 32, we need to know the size
2262 -- in the front end to activate possible packed array processing
2263 -- where the component type is a record.
2265 -- At this stage Hbit + 1 represents the first unused bit from all
2266 -- the component clauses processed, so if the component clauses are
2267 -- complete, then this is the length of the record.
2269 -- For records longer than System.Storage_Unit, and for those where
2270 -- not all components have component clauses, the back end determines
2271 -- the length (it may for example be appopriate to round up the size
2272 -- to some convenient boundary, based on alignment considerations etc).
2274 if Unknown_RM_Size
(Rectype
)
2275 and then Hbit
+ 1 <= 32
2277 -- Nothing to do if at least one component with no component clause
2279 Comp
:= First_Entity
(Rectype
);
2280 while Present
(Comp
) loop
2281 if Ekind
(Comp
) = E_Component
2282 or else Ekind
(Comp
) = E_Discriminant
2284 exit when No
(Component_Clause
(Comp
));
2290 -- If we fall out of loop, all components have component clauses
2291 -- and so we can set the size to the maximum value.
2294 Set_RM_Size
(Rectype
, Hbit
+ 1);
2298 -- Check missing components if Complete_Representation pragma appeared
2300 if Present
(CR_Pragma
) then
2301 Comp
:= First_Entity
(Rectype
);
2302 while Present
(Comp
) loop
2303 if Ekind
(Comp
) = E_Component
2305 Ekind
(Comp
) = E_Discriminant
2307 if No
(Component_Clause
(Comp
)) then
2309 ("missing component clause for &", CR_Pragma
, Comp
);
2316 end Analyze_Record_Representation_Clause
;
2318 -----------------------------
2319 -- Check_Component_Overlap --
2320 -----------------------------
2322 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
2324 if Present
(Component_Clause
(C1_Ent
))
2325 and then Present
(Component_Clause
(C2_Ent
))
2327 -- Exclude odd case where we have two tag fields in the same
2328 -- record, both at location zero. This seems a bit strange,
2329 -- but it seems to happen in some circumstances ???
2331 if Chars
(C1_Ent
) = Name_uTag
2332 and then Chars
(C2_Ent
) = Name_uTag
2337 -- Here we check if the two fields overlap
2340 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
2341 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
2342 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
2343 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
2346 if E2
<= S1
or else E1
<= S2
then
2350 Component_Name
(Component_Clause
(C2_Ent
));
2351 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
2353 Component_Name
(Component_Clause
(C1_Ent
));
2355 ("component& overlaps & #",
2356 Component_Name
(Component_Clause
(C1_Ent
)));
2360 end Check_Component_Overlap
;
2362 -----------------------------------
2363 -- Check_Constant_Address_Clause --
2364 -----------------------------------
2366 procedure Check_Constant_Address_Clause
2370 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
2371 -- Checks that the given node N represents a name whose 'Address
2372 -- is constant (in the same sense as OK_Constant_Address_Clause,
2373 -- i.e. the address value is the same at the point of declaration
2374 -- of U_Ent and at the time of elaboration of the address clause.
2376 procedure Check_Expr_Constants
(Nod
: Node_Id
);
2377 -- Checks that Nod meets the requirements for a constant address
2378 -- clause in the sense of the enclosing procedure.
2380 procedure Check_List_Constants
(Lst
: List_Id
);
2381 -- Check that all elements of list Lst meet the requirements for a
2382 -- constant address clause in the sense of the enclosing procedure.
2384 -------------------------------
2385 -- Check_At_Constant_Address --
2386 -------------------------------
2388 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
2390 if Is_Entity_Name
(Nod
) then
2391 if Present
(Address_Clause
(Entity
((Nod
)))) then
2393 ("invalid address clause for initialized object &!",
2396 ("address for& cannot" &
2397 " depend on another address clause! ('R'M 13.1(22))!",
2400 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
2401 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
2404 ("invalid address clause for initialized object &!",
2406 Error_Msg_Name_1
:= Chars
(Entity
(Nod
));
2407 Error_Msg_Name_2
:= Chars
(U_Ent
);
2409 ("\% must be defined before % ('R'M 13.1(22))!",
2413 elsif Nkind
(Nod
) = N_Selected_Component
then
2415 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
2418 if (Is_Record_Type
(T
)
2419 and then Has_Discriminants
(T
))
2422 and then Is_Record_Type
(Designated_Type
(T
))
2423 and then Has_Discriminants
(Designated_Type
(T
)))
2426 ("invalid address clause for initialized object &!",
2429 ("\address cannot depend on component" &
2430 " of discriminated record ('R'M 13.1(22))!",
2433 Check_At_Constant_Address
(Prefix
(Nod
));
2437 elsif Nkind
(Nod
) = N_Indexed_Component
then
2438 Check_At_Constant_Address
(Prefix
(Nod
));
2439 Check_List_Constants
(Expressions
(Nod
));
2442 Check_Expr_Constants
(Nod
);
2444 end Check_At_Constant_Address
;
2446 --------------------------
2447 -- Check_Expr_Constants --
2448 --------------------------
2450 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
2451 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
2452 Ent
: Entity_Id
:= Empty
;
2455 if Nkind
(Nod
) in N_Has_Etype
2456 and then Etype
(Nod
) = Any_Type
2462 when N_Empty | N_Error
=>
2465 when N_Identifier | N_Expanded_Name
=>
2466 Ent
:= Entity
(Nod
);
2468 -- We need to look at the original node if it is different
2469 -- from the node, since we may have rewritten things and
2470 -- substituted an identifier representing the rewrite.
2472 if Original_Node
(Nod
) /= Nod
then
2473 Check_Expr_Constants
(Original_Node
(Nod
));
2475 -- If the node is an object declaration without initial
2476 -- value, some code has been expanded, and the expression
2477 -- is not constant, even if the constituents might be
2478 -- acceptable, as in A'Address + offset.
2480 if Ekind
(Ent
) = E_Variable
2481 and then Nkind
(Declaration_Node
(Ent
))
2482 = N_Object_Declaration
2484 No
(Expression
(Declaration_Node
(Ent
)))
2487 ("invalid address clause for initialized object &!",
2490 -- If entity is constant, it may be the result of expanding
2491 -- a check. We must verify that its declaration appears
2492 -- before the object in question, else we also reject the
2495 elsif Ekind
(Ent
) = E_Constant
2496 and then In_Same_Source_Unit
(Ent
, U_Ent
)
2497 and then Sloc
(Ent
) > Loc_U_Ent
2500 ("invalid address clause for initialized object &!",
2507 -- Otherwise look at the identifier and see if it is OK
2509 if Ekind
(Ent
) = E_Named_Integer
2511 Ekind
(Ent
) = E_Named_Real
2518 Ekind
(Ent
) = E_Constant
2520 Ekind
(Ent
) = E_In_Parameter
2522 -- This is the case where we must have Ent defined
2523 -- before U_Ent. Clearly if they are in different
2524 -- units this requirement is met since the unit
2525 -- containing Ent is already processed.
2527 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
2530 -- Otherwise location of Ent must be before the
2531 -- location of U_Ent, that's what prior defined means.
2533 elsif Sloc
(Ent
) < Loc_U_Ent
then
2538 ("invalid address clause for initialized object &!",
2540 Error_Msg_Name_1
:= Chars
(Ent
);
2541 Error_Msg_Name_2
:= Chars
(U_Ent
);
2543 ("\% must be defined before % ('R'M 13.1(22))!",
2547 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2548 Check_Expr_Constants
(Original_Node
(Nod
));
2552 ("invalid address clause for initialized object &!",
2555 if Comes_From_Source
(Ent
) then
2556 Error_Msg_Name_1
:= Chars
(Ent
);
2558 ("\reference to variable% not allowed"
2559 & " ('R'M 13.1(22))!", Nod
);
2562 ("non-static expression not allowed"
2563 & " ('R'M 13.1(22))!", Nod
);
2567 when N_Integer_Literal
=>
2569 -- If this is a rewritten unchecked conversion, in a system
2570 -- where Address is an integer type, always use the base type
2571 -- for a literal value. This is user-friendly and prevents
2572 -- order-of-elaboration issues with instances of unchecked
2575 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2576 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2579 when N_Real_Literal |
2581 N_Character_Literal
=>
2585 Check_Expr_Constants
(Low_Bound
(Nod
));
2586 Check_Expr_Constants
(High_Bound
(Nod
));
2588 when N_Explicit_Dereference
=>
2589 Check_Expr_Constants
(Prefix
(Nod
));
2591 when N_Indexed_Component
=>
2592 Check_Expr_Constants
(Prefix
(Nod
));
2593 Check_List_Constants
(Expressions
(Nod
));
2596 Check_Expr_Constants
(Prefix
(Nod
));
2597 Check_Expr_Constants
(Discrete_Range
(Nod
));
2599 when N_Selected_Component
=>
2600 Check_Expr_Constants
(Prefix
(Nod
));
2602 when N_Attribute_Reference
=>
2603 if Attribute_Name
(Nod
) = Name_Address
2605 Attribute_Name
(Nod
) = Name_Access
2607 Attribute_Name
(Nod
) = Name_Unchecked_Access
2609 Attribute_Name
(Nod
) = Name_Unrestricted_Access
2611 Check_At_Constant_Address
(Prefix
(Nod
));
2614 Check_Expr_Constants
(Prefix
(Nod
));
2615 Check_List_Constants
(Expressions
(Nod
));
2619 Check_List_Constants
(Component_Associations
(Nod
));
2620 Check_List_Constants
(Expressions
(Nod
));
2622 when N_Component_Association
=>
2623 Check_Expr_Constants
(Expression
(Nod
));
2625 when N_Extension_Aggregate
=>
2626 Check_Expr_Constants
(Ancestor_Part
(Nod
));
2627 Check_List_Constants
(Component_Associations
(Nod
));
2628 Check_List_Constants
(Expressions
(Nod
));
2633 when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In
=>
2634 Check_Expr_Constants
(Left_Opnd
(Nod
));
2635 Check_Expr_Constants
(Right_Opnd
(Nod
));
2638 Check_Expr_Constants
(Right_Opnd
(Nod
));
2640 when N_Type_Conversion |
2641 N_Qualified_Expression |
2643 Check_Expr_Constants
(Expression
(Nod
));
2645 when N_Unchecked_Type_Conversion
=>
2646 Check_Expr_Constants
(Expression
(Nod
));
2648 -- If this is a rewritten unchecked conversion, subtypes
2649 -- in this node are those created within the instance.
2650 -- To avoid order of elaboration issues, replace them
2651 -- with their base types. Note that address clauses can
2652 -- cause order of elaboration problems because they are
2653 -- elaborated by the back-end at the point of definition,
2654 -- and may mention entities declared in between (as long
2655 -- as everything is static). It is user-friendly to allow
2656 -- unchecked conversions in this context.
2658 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2659 Set_Etype
(Expression
(Nod
),
2660 Base_Type
(Etype
(Expression
(Nod
))));
2661 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2664 when N_Function_Call
=>
2665 if not Is_Pure
(Entity
(Name
(Nod
))) then
2667 ("invalid address clause for initialized object &!",
2671 ("\function & is not pure ('R'M 13.1(22))!",
2672 Nod
, Entity
(Name
(Nod
)));
2675 Check_List_Constants
(Parameter_Associations
(Nod
));
2678 when N_Parameter_Association
=>
2679 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
2683 ("invalid address clause for initialized object &!",
2686 ("\must be constant defined before& ('R'M 13.1(22))!",
2689 end Check_Expr_Constants
;
2691 --------------------------
2692 -- Check_List_Constants --
2693 --------------------------
2695 procedure Check_List_Constants
(Lst
: List_Id
) is
2699 if Present
(Lst
) then
2700 Nod1
:= First
(Lst
);
2701 while Present
(Nod1
) loop
2702 Check_Expr_Constants
(Nod1
);
2706 end Check_List_Constants
;
2708 -- Start of processing for Check_Constant_Address_Clause
2711 Check_Expr_Constants
(Expr
);
2712 end Check_Constant_Address_Clause
;
2718 procedure Check_Size
2722 Biased
: out Boolean)
2724 UT
: constant Entity_Id
:= Underlying_Type
(T
);
2730 -- Dismiss cases for generic types or types with previous errors
2733 or else UT
= Any_Type
2734 or else Is_Generic_Type
(UT
)
2735 or else Is_Generic_Type
(Root_Type
(UT
))
2739 -- Check case of bit packed array
2741 elsif Is_Array_Type
(UT
)
2742 and then Known_Static_Component_Size
(UT
)
2743 and then Is_Bit_Packed_Array
(UT
)
2751 Asiz
:= Component_Size
(UT
);
2752 Indx
:= First_Index
(UT
);
2754 Ityp
:= Etype
(Indx
);
2756 -- If non-static bound, then we are not in the business of
2757 -- trying to check the length, and indeed an error will be
2758 -- issued elsewhere, since sizes of non-static array types
2759 -- cannot be set implicitly or explicitly.
2761 if not Is_Static_Subtype
(Ityp
) then
2765 -- Otherwise accumulate next dimension
2767 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
2768 Expr_Value
(Type_Low_Bound
(Ityp
)) +
2772 exit when No
(Indx
);
2778 Error_Msg_Uint_1
:= Asiz
;
2780 ("size for& too small, minimum allowed is ^", N
, T
);
2781 Set_Esize
(T
, Asiz
);
2782 Set_RM_Size
(T
, Asiz
);
2786 -- All other composite types are ignored
2788 elsif Is_Composite_Type
(UT
) then
2791 -- For fixed-point types, don't check minimum if type is not frozen,
2792 -- since we don't know all the characteristics of the type that can
2793 -- affect the size (e.g. a specified small) till freeze time.
2795 elsif Is_Fixed_Point_Type
(UT
)
2796 and then not Is_Frozen
(UT
)
2800 -- Cases for which a minimum check is required
2803 -- Ignore if specified size is correct for the type
2805 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
2809 -- Otherwise get minimum size
2811 M
:= UI_From_Int
(Minimum_Size
(UT
));
2815 -- Size is less than minimum size, but one possibility remains
2816 -- that we can manage with the new size if we bias the type
2818 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
2821 Error_Msg_Uint_1
:= M
;
2823 ("size for& too small, minimum allowed is ^", N
, T
);
2833 -------------------------
2834 -- Get_Alignment_Value --
2835 -------------------------
2837 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
2838 Align
: constant Uint
:= Static_Integer
(Expr
);
2841 if Align
= No_Uint
then
2844 elsif Align
<= 0 then
2845 Error_Msg_N
("alignment value must be positive", Expr
);
2849 for J
in Int
range 0 .. 64 loop
2851 M
: constant Uint
:= Uint_2
** J
;
2854 exit when M
= Align
;
2858 ("alignment value must be power of 2", Expr
);
2866 end Get_Alignment_Value
;
2872 procedure Initialize
is
2874 Unchecked_Conversions
.Init
;
2877 -------------------------
2878 -- Is_Operational_Item --
2879 -------------------------
2881 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
2883 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
2887 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
2890 return Id
= Attribute_Input
2891 or else Id
= Attribute_Output
2892 or else Id
= Attribute_Read
2893 or else Id
= Attribute_Write
2894 or else Id
= Attribute_External_Tag
;
2897 end Is_Operational_Item
;
2899 --------------------------------------
2900 -- Mark_Aliased_Address_As_Volatile --
2901 --------------------------------------
2903 procedure Mark_Aliased_Address_As_Volatile
(N
: Node_Id
) is
2904 Ent
: constant Entity_Id
:= Address_Aliased_Entity
(N
);
2907 if Present
(Ent
) then
2908 Set_Treat_As_Volatile
(Ent
);
2910 end Mark_Aliased_Address_As_Volatile
;
2916 function Minimum_Size
2918 Biased
: Boolean := False) return Nat
2920 Lo
: Uint
:= No_Uint
;
2921 Hi
: Uint
:= No_Uint
;
2922 LoR
: Ureal
:= No_Ureal
;
2923 HiR
: Ureal
:= No_Ureal
;
2924 LoSet
: Boolean := False;
2925 HiSet
: Boolean := False;
2929 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
2932 -- If bad type, return 0
2934 if T
= Any_Type
then
2937 -- For generic types, just return zero. There cannot be any legitimate
2938 -- need to know such a size, but this routine may be called with a
2939 -- generic type as part of normal processing.
2941 elsif Is_Generic_Type
(R_Typ
)
2942 or else R_Typ
= Any_Type
2946 -- Access types. Normally an access type cannot have a size smaller
2947 -- than the size of System.Address. The exception is on VMS, where
2948 -- we have short and long addresses, and it is possible for an access
2949 -- type to have a short address size (and thus be less than the size
2950 -- of System.Address itself). We simply skip the check for VMS, and
2951 -- leave the back end to do the check.
2953 elsif Is_Access_Type
(T
) then
2954 if OpenVMS_On_Target
then
2957 return System_Address_Size
;
2960 -- Floating-point types
2962 elsif Is_Floating_Point_Type
(T
) then
2963 return UI_To_Int
(Esize
(R_Typ
));
2967 elsif Is_Discrete_Type
(T
) then
2969 -- The following loop is looking for the nearest compile time
2970 -- known bounds following the ancestor subtype chain. The idea
2971 -- is to find the most restrictive known bounds information.
2975 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
2980 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
2981 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
2988 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
2989 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
2995 Ancest
:= Ancestor_Subtype
(Ancest
);
2998 Ancest
:= Base_Type
(T
);
3000 if Is_Generic_Type
(Ancest
) then
3006 -- Fixed-point types. We can't simply use Expr_Value to get the
3007 -- Corresponding_Integer_Value values of the bounds, since these
3008 -- do not get set till the type is frozen, and this routine can
3009 -- be called before the type is frozen. Similarly the test for
3010 -- bounds being static needs to include the case where we have
3011 -- unanalyzed real literals for the same reason.
3013 elsif Is_Fixed_Point_Type
(T
) then
3015 -- The following loop is looking for the nearest compile time
3016 -- known bounds following the ancestor subtype chain. The idea
3017 -- is to find the most restrictive known bounds information.
3021 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
3026 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
3027 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
3029 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
3036 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
3037 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
3039 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
3045 Ancest
:= Ancestor_Subtype
(Ancest
);
3048 Ancest
:= Base_Type
(T
);
3050 if Is_Generic_Type
(Ancest
) then
3056 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
3057 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
3059 -- No other types allowed
3062 raise Program_Error
;
3065 -- Fall through with Hi and Lo set. Deal with biased case
3067 if (Biased
and then not Is_Fixed_Point_Type
(T
))
3068 or else Has_Biased_Representation
(T
)
3074 -- Signed case. Note that we consider types like range 1 .. -1 to be
3075 -- signed for the purpose of computing the size, since the bounds
3076 -- have to be accomodated in the base type.
3078 if Lo
< 0 or else Hi
< 0 then
3082 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3083 -- Note that we accommodate the case where the bounds cross. This
3084 -- can happen either because of the way the bounds are declared
3085 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3099 -- If both bounds are positive, make sure that both are represen-
3100 -- table in the case where the bounds are crossed. This can happen
3101 -- either because of the way the bounds are declared, or because of
3102 -- the algorithm in Freeze_Fixed_Point_Type.
3108 -- S = size, (can accommodate 0 .. (2**size - 1))
3111 while Hi
>= Uint_2
** S
loop
3119 -------------------------
3120 -- New_Stream_Function --
3121 -------------------------
3123 procedure New_Stream_Function
3127 Nam
: TSS_Name_Type
)
3129 Loc
: constant Source_Ptr
:= Sloc
(N
);
3130 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3131 Subp_Id
: Entity_Id
;
3132 Subp_Decl
: Node_Id
;
3136 function Build_Spec
return Node_Id
;
3137 -- Used for declaration and renaming declaration, so that this is
3138 -- treated as a renaming_as_body.
3144 function Build_Spec
return Node_Id
is
3146 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3149 Make_Function_Specification
(Loc
,
3150 Defining_Unit_Name
=> Subp_Id
,
3151 Parameter_Specifications
=>
3153 Make_Parameter_Specification
(Loc
,
3154 Defining_Identifier
=>
3155 Make_Defining_Identifier
(Loc
, Name_S
),
3157 Make_Access_Definition
(Loc
,
3160 Designated_Type
(Etype
(F
)), Loc
)))),
3162 Result_Definition
=>
3163 New_Reference_To
(Etyp
, Loc
));
3166 -- Start of processing for New_Stream_Function
3169 F
:= First_Formal
(Subp
);
3170 Etyp
:= Etype
(Subp
);
3172 if not Is_Tagged_Type
(Ent
) then
3174 Make_Subprogram_Declaration
(Loc
,
3175 Specification
=> Build_Spec
);
3176 Insert_Action
(N
, Subp_Decl
);
3180 Make_Subprogram_Renaming_Declaration
(Loc
,
3181 Specification
=> Build_Spec
,
3182 Name
=> New_Reference_To
(Subp
, Loc
));
3184 if Is_Tagged_Type
(Ent
) then
3185 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3187 Insert_Action
(N
, Subp_Decl
);
3188 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3190 end New_Stream_Function
;
3192 --------------------------
3193 -- New_Stream_Procedure --
3194 --------------------------
3196 procedure New_Stream_Procedure
3200 Nam
: TSS_Name_Type
;
3201 Out_P
: Boolean := False)
3203 Loc
: constant Source_Ptr
:= Sloc
(N
);
3204 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3205 Subp_Id
: Entity_Id
;
3206 Subp_Decl
: Node_Id
;
3210 function Build_Spec
return Node_Id
;
3211 -- Used for declaration and renaming declaration, so that this is
3212 -- treated as a renaming_as_body.
3218 function Build_Spec
return Node_Id
is
3220 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3223 Make_Procedure_Specification
(Loc
,
3224 Defining_Unit_Name
=> Subp_Id
,
3225 Parameter_Specifications
=>
3227 Make_Parameter_Specification
(Loc
,
3228 Defining_Identifier
=>
3229 Make_Defining_Identifier
(Loc
, Name_S
),
3231 Make_Access_Definition
(Loc
,
3234 Designated_Type
(Etype
(F
)), Loc
))),
3236 Make_Parameter_Specification
(Loc
,
3237 Defining_Identifier
=>
3238 Make_Defining_Identifier
(Loc
, Name_V
),
3239 Out_Present
=> Out_P
,
3241 New_Reference_To
(Etyp
, Loc
))));
3244 -- Start of processing for New_Stream_Procedure
3247 F
:= First_Formal
(Subp
);
3248 Etyp
:= Etype
(Next_Formal
(F
));
3250 if not Is_Tagged_Type
(Ent
) then
3252 Make_Subprogram_Declaration
(Loc
,
3253 Specification
=> Build_Spec
);
3254 Insert_Action
(N
, Subp_Decl
);
3258 Make_Subprogram_Renaming_Declaration
(Loc
,
3259 Specification
=> Build_Spec
,
3260 Name
=> New_Reference_To
(Subp
, Loc
));
3262 if Is_Tagged_Type
(Ent
) then
3263 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3265 Insert_Action
(N
, Subp_Decl
);
3266 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3268 end New_Stream_Procedure
;
3270 ------------------------
3271 -- Rep_Item_Too_Early --
3272 ------------------------
3274 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
3276 -- Cannot apply rep items that are not operational items
3279 if Is_Operational_Item
(N
) then
3283 and then Is_Generic_Type
(Root_Type
(T
))
3286 ("representation item not allowed for generic type", N
);
3290 -- Otherwise check for incompleted type
3292 if Is_Incomplete_Or_Private_Type
(T
)
3293 and then No
(Underlying_Type
(T
))
3296 ("representation item must be after full type declaration", N
);
3299 -- If the type has incompleted components, a representation clause is
3300 -- illegal but stream attributes and Convention pragmas are correct.
3302 elsif Has_Private_Component
(T
) then
3303 if Nkind
(N
) = N_Pragma
then
3307 ("representation item must appear after type is fully defined",
3314 end Rep_Item_Too_Early
;
3316 -----------------------
3317 -- Rep_Item_Too_Late --
3318 -----------------------
3320 function Rep_Item_Too_Late
3323 FOnly
: Boolean := False) return Boolean
3326 Parent_Type
: Entity_Id
;
3329 -- Output the too late message. Note that this is not considered a
3330 -- serious error, since the effect is simply that we ignore the
3331 -- representation clause in this case.
3337 procedure Too_Late
is
3339 Error_Msg_N
("|representation item appears too late!", N
);
3342 -- Start of processing for Rep_Item_Too_Late
3345 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3346 -- types, which may be frozen if they appear in a representation clause
3347 -- for a local type.
3350 and then not From_With_Type
(T
)
3353 S
:= First_Subtype
(T
);
3355 if Present
(Freeze_Node
(S
)) then
3357 ("?no more representation items for }", Freeze_Node
(S
), S
);
3362 -- Check for case of non-tagged derived type whose parent either has
3363 -- primitive operations, or is a by reference type (RM 13.1(10)).
3367 and then Is_Derived_Type
(T
)
3368 and then not Is_Tagged_Type
(T
)
3370 Parent_Type
:= Etype
(Base_Type
(T
));
3372 if Has_Primitive_Operations
(Parent_Type
) then
3375 ("primitive operations already defined for&!", N
, Parent_Type
);
3378 elsif Is_By_Reference_Type
(Parent_Type
) then
3381 ("parent type & is a by reference type!", N
, Parent_Type
);
3386 -- No error, link item into head of chain of rep items for the entity
3388 Record_Rep_Item
(T
, N
);
3390 end Rep_Item_Too_Late
;
3392 -------------------------
3393 -- Same_Representation --
3394 -------------------------
3396 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
3397 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
3398 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
3401 -- A quick check, if base types are the same, then we definitely have
3402 -- the same representation, because the subtype specific representation
3403 -- attributes (Size and Alignment) do not affect representation from
3404 -- the point of view of this test.
3406 if Base_Type
(T1
) = Base_Type
(T2
) then
3409 elsif Is_Private_Type
(Base_Type
(T2
))
3410 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
3415 -- Tagged types never have differing representations
3417 if Is_Tagged_Type
(T1
) then
3421 -- Representations are definitely different if conventions differ
3423 if Convention
(T1
) /= Convention
(T2
) then
3427 -- Representations are different if component alignments differ
3429 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
3431 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
3432 and then Component_Alignment
(T1
) /= Component_Alignment
(T2
)
3437 -- For arrays, the only real issue is component size. If we know the
3438 -- component size for both arrays, and it is the same, then that's
3439 -- good enough to know we don't have a change of representation.
3441 if Is_Array_Type
(T1
) then
3442 if Known_Component_Size
(T1
)
3443 and then Known_Component_Size
(T2
)
3444 and then Component_Size
(T1
) = Component_Size
(T2
)
3450 -- Types definitely have same representation if neither has non-standard
3451 -- representation since default representations are always consistent.
3452 -- If only one has non-standard representation, and the other does not,
3453 -- then we consider that they do not have the same representation. They
3454 -- might, but there is no way of telling early enough.
3456 if Has_Non_Standard_Rep
(T1
) then
3457 if not Has_Non_Standard_Rep
(T2
) then
3461 return not Has_Non_Standard_Rep
(T2
);
3464 -- Here the two types both have non-standard representation, and we
3465 -- need to determine if they have the same non-standard representation
3467 -- For arrays, we simply need to test if the component sizes are the
3468 -- same. Pragma Pack is reflected in modified component sizes, so this
3469 -- check also deals with pragma Pack.
3471 if Is_Array_Type
(T1
) then
3472 return Component_Size
(T1
) = Component_Size
(T2
);
3474 -- Tagged types always have the same representation, because it is not
3475 -- possible to specify different representations for common fields.
3477 elsif Is_Tagged_Type
(T1
) then
3480 -- Case of record types
3482 elsif Is_Record_Type
(T1
) then
3484 -- Packed status must conform
3486 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
3489 -- Otherwise we must check components. Typ2 maybe a constrained
3490 -- subtype with fewer components, so we compare the components
3491 -- of the base types.
3494 Record_Case
: declare
3495 CD1
, CD2
: Entity_Id
;
3497 function Same_Rep
return Boolean;
3498 -- CD1 and CD2 are either components or discriminants. This
3499 -- function tests whether the two have the same representation
3505 function Same_Rep
return Boolean is
3507 if No
(Component_Clause
(CD1
)) then
3508 return No
(Component_Clause
(CD2
));
3512 Present
(Component_Clause
(CD2
))
3514 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
3516 Esize
(CD1
) = Esize
(CD2
);
3520 -- Start processing for Record_Case
3523 if Has_Discriminants
(T1
) then
3524 CD1
:= First_Discriminant
(T1
);
3525 CD2
:= First_Discriminant
(T2
);
3527 -- The number of discriminants may be different if the
3528 -- derived type has fewer (constrained by values). The
3529 -- invisible discriminants retain the representation of
3530 -- the original, so the discrepancy does not per se
3531 -- indicate a different representation.
3534 and then Present
(CD2
)
3536 if not Same_Rep
then
3539 Next_Discriminant
(CD1
);
3540 Next_Discriminant
(CD2
);
3545 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
3546 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
3548 while Present
(CD1
) loop
3549 if not Same_Rep
then
3552 Next_Component
(CD1
);
3553 Next_Component
(CD2
);
3561 -- For enumeration types, we must check each literal to see if the
3562 -- representation is the same. Note that we do not permit enumeration
3563 -- reprsentation clauses for Character and Wide_Character, so these
3564 -- cases were already dealt with.
3566 elsif Is_Enumeration_Type
(T1
) then
3568 Enumeration_Case
: declare
3572 L1
:= First_Literal
(T1
);
3573 L2
:= First_Literal
(T2
);
3575 while Present
(L1
) loop
3576 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
3586 end Enumeration_Case
;
3588 -- Any other types have the same representation for these purposes
3593 end Same_Representation
;
3595 --------------------
3596 -- Set_Enum_Esize --
3597 --------------------
3599 procedure Set_Enum_Esize
(T
: Entity_Id
) is
3607 -- Find the minimum standard size (8,16,32,64) that fits
3609 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
3610 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
3613 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
3614 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3616 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
3619 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
3622 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
3627 if Hi
< Uint_2
**08 then
3628 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3630 elsif Hi
< Uint_2
**16 then
3633 elsif Hi
< Uint_2
**32 then
3636 else pragma Assert
(Hi
< Uint_2
**63);
3641 -- That minimum is the proper size unless we have a foreign convention
3642 -- and the size required is 32 or less, in which case we bump the size
3643 -- up to 32. This is required for C and C++ and seems reasonable for
3644 -- all other foreign conventions.
3646 if Has_Foreign_Convention
(T
)
3647 and then Esize
(T
) < Standard_Integer_Size
3649 Init_Esize
(T
, Standard_Integer_Size
);
3656 -----------------------------------
3657 -- Validate_Unchecked_Conversion --
3658 -----------------------------------
3660 procedure Validate_Unchecked_Conversion
3662 Act_Unit
: Entity_Id
)
3669 -- Obtain source and target types. Note that we call Ancestor_Subtype
3670 -- here because the processing for generic instantiation always makes
3671 -- subtypes, and we want the original frozen actual types.
3673 -- If we are dealing with private types, then do the check on their
3674 -- fully declared counterparts if the full declarations have been
3675 -- encountered (they don't have to be visible, but they must exist!)
3677 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
3679 if Is_Private_Type
(Source
)
3680 and then Present
(Underlying_Type
(Source
))
3682 Source
:= Underlying_Type
(Source
);
3685 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
3687 -- If either type is generic, the instantiation happens within a
3688 -- generic unit, and there is nothing to check. The proper check
3689 -- will happen when the enclosing generic is instantiated.
3691 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
3695 if Is_Private_Type
(Target
)
3696 and then Present
(Underlying_Type
(Target
))
3698 Target
:= Underlying_Type
(Target
);
3701 -- Source may be unconstrained array, but not target
3703 if Is_Array_Type
(Target
)
3704 and then not Is_Constrained
(Target
)
3707 ("unchecked conversion to unconstrained array not allowed", N
);
3711 -- Make entry in unchecked conversion table for later processing
3712 -- by Validate_Unchecked_Conversions, which will check sizes and
3713 -- alignments (using values set by the back-end where possible).
3714 -- This is only done if the appropriate warning is active
3716 if Warn_On_Unchecked_Conversion
then
3717 Unchecked_Conversions
.Append
3718 (New_Val
=> UC_Entry
'
3723 -- If both sizes are known statically now, then back end annotation
3724 -- is not required to do a proper check but if either size is not
3725 -- known statically, then we need the annotation.
3727 if Known_Static_RM_Size (Source)
3728 and then Known_Static_RM_Size (Target)
3732 Back_Annotate_Rep_Info := True;
3736 -- If unchecked conversion to access type, and access type is
3737 -- declared in the same unit as the unchecked conversion, then
3738 -- set the No_Strict_Aliasing flag (no strict aliasing is
3739 -- implicit in this situation).
3741 if Is_Access_Type (Target) and then
3742 In_Same_Source_Unit (Target, N)
3744 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
3747 -- Generate N_Validate_Unchecked_Conversion node for back end in
3748 -- case the back end needs to perform special validation checks.
3750 -- Shouldn't this be in exp_ch13, since the check only gets done
3751 -- if we have full expansion and the back end is called ???
3754 Make_Validate_Unchecked_Conversion (Sloc (N));
3755 Set_Source_Type (Vnode, Source);
3756 Set_Target_Type (Vnode, Target);
3758 -- If the unchecked conversion node is in a list, just insert before
3759 -- it. If not we have some strange case, not worth bothering about.
3761 if Is_List_Member (N) then
3762 Insert_After (N, Vnode);
3764 end Validate_Unchecked_Conversion;
3766 ------------------------------------
3767 -- Validate_Unchecked_Conversions --
3768 ------------------------------------
3770 procedure Validate_Unchecked_Conversions is
3772 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
3774 T : UC_Entry renames Unchecked_Conversions.Table (N);
3776 Enode : constant Node_Id := T.Enode;
3777 Source : constant Entity_Id := T.Source;
3778 Target : constant Entity_Id := T.Target;
3784 -- This validation check, which warns if we have unequal sizes
3785 -- for unchecked conversion, and thus potentially implementation
3786 -- dependent semantics, is one of the few occasions on which we
3787 -- use the official RM size instead of Esize. See description
3788 -- in Einfo "Handling of Type'Size Values" for details.
3790 if Serious_Errors_Detected = 0
3791 and then Known_Static_RM_Size (Source)
3792 and then Known_Static_RM_Size (Target)
3794 Source_Siz := RM_Size (Source);
3795 Target_Siz := RM_Size (Target);
3797 if Source_Siz /= Target_Siz then
3799 ("types for unchecked conversion have different sizes?",
3802 if All_Errors_Mode then
3803 Error_Msg_Name_1 := Chars (Source);
3804 Error_Msg_Uint_1 := Source_Siz;
3805 Error_Msg_Name_2 := Chars (Target);
3806 Error_Msg_Uint_2 := Target_Siz;
3808 ("\size of % is ^, size of % is ^?", Enode);
3810 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
3812 if Is_Discrete_Type (Source)
3813 and then Is_Discrete_Type (Target)
3815 if Source_Siz > Target_Siz then
3817 ("\^ high order bits of source will be ignored?",
3820 elsif Is_Unsigned_Type (Source) then
3822 ("\source will be extended with ^ high order " &
3823 "zero bits?", Enode);
3827 ("\source will be extended with ^ high order " &
3832 elsif Source_Siz < Target_Siz then
3833 if Is_Discrete_Type (Target) then
3834 if Bytes_Big_Endian then
3836 ("\target value will include ^ undefined " &
3841 ("\target value will include ^ undefined " &
3848 ("\^ trailing bits of target value will be " &
3849 "undefined?", Enode);
3852 else pragma Assert (Source_Siz > Target_Siz);
3854 ("\^ trailing bits of source will be ignored?",
3861 -- If both types are access types, we need to check the alignment.
3862 -- If the alignment of both is specified, we can do it here.
3864 if Serious_Errors_Detected = 0
3865 and then Ekind (Source) in Access_Kind
3866 and then Ekind (Target) in Access_Kind
3867 and then Target_Strict_Alignment
3868 and then Present (Designated_Type (Source))
3869 and then Present (Designated_Type (Target))
3872 D_Source : constant Entity_Id := Designated_Type (Source);
3873 D_Target : constant Entity_Id := Designated_Type (Target);
3876 if Known_Alignment (D_Source)
3877 and then Known_Alignment (D_Target)
3880 Source_Align : constant Uint := Alignment (D_Source);
3881 Target_Align : constant Uint := Alignment (D_Target);
3884 if Source_Align < Target_Align
3885 and then not Is_Tagged_Type (D_Source)
3887 Error_Msg_Uint_1 := Target_Align;
3888 Error_Msg_Uint_2 := Source_Align;
3889 Error_Msg_Node_2 := D_Source;
3891 ("alignment of & (^) is stricter than " &
3892 "alignment of & (^)?", Enode, D_Target);
3894 if All_Errors_Mode then
3896 ("\resulting access value may have invalid " &
3897 "alignment?", Enode);
3906 end Validate_Unchecked_Conversions;