1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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.
251 if Rep_Item_Too_Early
(Ent
, N
) then
255 -- Rep clause applies to full view of incomplete type or private type
256 -- if we have one (if not, this is a premature use of the type).
257 -- However, certain semantic checks need to be done on the specified
258 -- entity (i.e. the private view), so we save it in Ent.
260 if Is_Private_Type
(Ent
)
261 and then Is_Derived_Type
(Ent
)
262 and then not Is_Tagged_Type
(Ent
)
263 and then No
(Full_View
(Ent
))
265 -- If this is a private type whose completion is a derivation
266 -- from another private type, there is no full view, and the
267 -- attribute belongs to the type itself, not its underlying parent.
271 elsif Ekind
(Ent
) = E_Incomplete_Type
then
273 -- The attribute applies to the full view, set the entity
274 -- of the attribute definition accordingly.
276 Ent
:= Underlying_Type
(Ent
);
278 Set_Entity
(Nam
, Ent
);
281 U_Ent
:= Underlying_Type
(Ent
);
284 -- Complete other routine error checks
286 if Etype
(Nam
) = Any_Type
then
289 elsif Scope
(Ent
) /= Current_Scope
then
290 Error_Msg_N
("entity must be declared in this scope", Nam
);
293 elsif No
(U_Ent
) then
296 elsif Is_Type
(U_Ent
)
297 and then not Is_First_Subtype
(U_Ent
)
298 and then Id
/= Attribute_Object_Size
299 and then Id
/= Attribute_Value_Size
300 and then not From_At_Mod
(N
)
302 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
306 -- Switch on particular attribute
314 -- Address attribute definition clause
316 when Attribute_Address
=> Address
: begin
317 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
319 if Present
(Address_Clause
(U_Ent
)) then
320 Error_Msg_N
("address already given for &", Nam
);
322 -- Case of address clause for subprogram
324 elsif Is_Subprogram
(U_Ent
) then
325 if Has_Homonym
(U_Ent
) then
327 ("address clause cannot be given " &
328 "for overloaded subprogram",
332 -- For subprograms, all address clauses are permitted,
333 -- and we mark the subprogram as having a deferred freeze
334 -- so that Gigi will not elaborate it too soon.
336 -- Above needs more comments, what is too soon about???
338 Set_Has_Delayed_Freeze
(U_Ent
);
340 -- Case of address clause for entry
342 elsif Ekind
(U_Ent
) = E_Entry
then
343 if Nkind
(Parent
(N
)) = N_Task_Body
then
345 ("entry address must be specified in task spec", Nam
);
348 -- For entries, we require a constant address
350 Check_Constant_Address_Clause
(Expr
, U_Ent
);
352 if Is_Task_Type
(Scope
(U_Ent
))
353 and then Comes_From_Source
(Scope
(U_Ent
))
356 ("?entry address declared for entry in task type", N
);
358 ("\?only one task can be declared of this type", N
);
361 Check_Restriction
(No_Obsolescent_Features
, N
);
363 if Warn_On_Obsolescent_Feature
then
365 ("attaching interrupt to task entry is an " &
366 "obsolescent feature ('R'M 'J.7.1)?", N
);
368 ("\use interrupt procedure instead?", N
);
371 -- Case of an address clause for a controlled object:
372 -- erroneous execution.
374 elsif Is_Controlled
(Etype
(U_Ent
)) then
376 ("?controlled object& must not be overlaid", Nam
, U_Ent
);
378 ("\?Program_Error will be raised at run time", Nam
);
379 Insert_Action
(Declaration_Node
(U_Ent
),
380 Make_Raise_Program_Error
(Loc
,
381 Reason
=> PE_Overlaid_Controlled_Object
));
383 -- Case of address clause for a (non-controlled) object
386 Ekind
(U_Ent
) = E_Variable
388 Ekind
(U_Ent
) = E_Constant
391 Expr
: constant Node_Id
:= Expression
(N
);
392 Aent
: constant Entity_Id
:= Address_Aliased_Entity
(Expr
);
395 -- Exported variables cannot have an address clause,
396 -- because this cancels the effect of the pragma Export
398 if Is_Exported
(U_Ent
) then
400 ("cannot export object with address clause", Nam
);
402 -- Overlaying controlled objects is erroneous
405 and then Is_Controlled
(Etype
(Aent
))
408 ("?controlled object must not be overlaid", Expr
);
410 ("\?Program_Error will be raised at run time", Expr
);
411 Insert_Action
(Declaration_Node
(U_Ent
),
412 Make_Raise_Program_Error
(Loc
,
413 Reason
=> PE_Overlaid_Controlled_Object
));
416 and then Ekind
(U_Ent
) = E_Constant
417 and then Ekind
(Aent
) /= E_Constant
419 Error_Msg_N
("constant overlays a variable?", Expr
);
421 elsif Present
(Renamed_Object
(U_Ent
)) then
423 ("address clause not allowed"
424 & " for a renaming declaration ('R'M 13.1(6))", Nam
);
426 -- Imported variables can have an address clause, but then
427 -- the import is pretty meaningless except to suppress
428 -- initializations, so we do not need such variables to
429 -- be statically allocated (and in fact it causes trouble
430 -- if the address clause is a local value).
432 elsif Is_Imported
(U_Ent
) then
433 Set_Is_Statically_Allocated
(U_Ent
, False);
436 -- We mark a possible modification of a variable with an
437 -- address clause, since it is likely aliasing is occurring.
439 Note_Possible_Modification
(Nam
);
441 -- Here we are checking for explicit overlap of one
442 -- variable by another, and if we find this, then we
443 -- mark the overlapped variable as also being aliased.
445 -- First case is where we have an explicit
447 -- for J'Address use K'Address;
449 -- In this case, we mark K as volatile
451 Mark_Aliased_Address_As_Volatile
(Expr
);
453 -- Second case is where we have a constant whose
454 -- definition is of the form of an adress as in:
456 -- A : constant Address := K'Address;
458 -- for B'Address use A;
460 -- In this case we also mark K as volatile
462 if Is_Entity_Name
(Expr
) then
464 Ent
: constant Entity_Id
:= Entity
(Expr
);
465 Decl
: constant Node_Id
:= Declaration_Node
(Ent
);
468 if Ekind
(Ent
) = E_Constant
469 and then Nkind
(Decl
) = N_Object_Declaration
470 and then Present
(Expression
(Decl
))
472 Mark_Aliased_Address_As_Volatile
478 -- Legality checks on the address clause for initialized
479 -- objects is deferred until the freeze point, because
480 -- a subsequent pragma might indicate that the object is
481 -- imported and thus not initialized.
483 Set_Has_Delayed_Freeze
(U_Ent
);
485 if Is_Exported
(U_Ent
) then
487 ("& cannot be exported if an address clause is given",
490 ("\define and export a variable " &
491 "that holds its address instead",
495 -- Entity has delayed freeze, so we will generate
496 -- an alignment check at the freeze point.
498 Set_Check_Address_Alignment
499 (N
, not Range_Checks_Suppressed
(U_Ent
));
501 -- Kill the size check code, since we are not allocating
502 -- the variable, it is somewhere else.
504 Kill_Size_Check_Code
(U_Ent
);
507 -- Not a valid entity for an address clause
510 Error_Msg_N
("address cannot be given for &", Nam
);
518 -- Alignment attribute definition clause
520 when Attribute_Alignment
=> Alignment_Block
: declare
521 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
526 if not Is_Type
(U_Ent
)
527 and then Ekind
(U_Ent
) /= E_Variable
528 and then Ekind
(U_Ent
) /= E_Constant
530 Error_Msg_N
("alignment cannot be given for &", Nam
);
532 elsif Has_Alignment_Clause
(U_Ent
) then
533 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
534 Error_Msg_N
("alignment clause previously given#", N
);
536 elsif Align
/= No_Uint
then
537 Set_Has_Alignment_Clause
(U_Ent
);
538 Set_Alignment
(U_Ent
, Align
);
546 -- Bit_Order attribute definition clause
548 when Attribute_Bit_Order
=> Bit_Order
: declare
550 if not Is_Record_Type
(U_Ent
) then
552 ("Bit_Order can only be defined for record type", Nam
);
555 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
557 if Etype
(Expr
) = Any_Type
then
560 elsif not Is_Static_Expression
(Expr
) then
562 ("Bit_Order requires static expression!", Expr
);
565 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
566 Set_Reverse_Bit_Order
(U_Ent
, True);
576 -- Component_Size attribute definition clause
578 when Attribute_Component_Size
=> Component_Size_Case
: declare
579 Csize
: constant Uint
:= Static_Integer
(Expr
);
582 New_Ctyp
: Entity_Id
;
586 if not Is_Array_Type
(U_Ent
) then
587 Error_Msg_N
("component size requires array type", Nam
);
591 Btype
:= Base_Type
(U_Ent
);
593 if Has_Component_Size_Clause
(Btype
) then
595 ("component size clase for& previously given", Nam
);
597 elsif Csize
/= No_Uint
then
598 Check_Size
(Expr
, Component_Type
(Btype
), Csize
, Biased
);
600 if Has_Aliased_Components
(Btype
)
606 ("component size incorrect for aliased components", N
);
610 -- For the biased case, build a declaration for a subtype
611 -- that will be used to represent the biased subtype that
612 -- reflects the biased representation of components. We need
613 -- this subtype to get proper conversions on referencing
614 -- elements of the array.
618 Make_Defining_Identifier
(Loc
,
619 Chars
=> New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
622 Make_Subtype_Declaration
(Loc
,
623 Defining_Identifier
=> New_Ctyp
,
624 Subtype_Indication
=>
625 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
627 Set_Parent
(Decl
, N
);
628 Analyze
(Decl
, Suppress
=> All_Checks
);
630 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
631 Set_Esize
(New_Ctyp
, Csize
);
632 Set_RM_Size
(New_Ctyp
, Csize
);
633 Init_Alignment
(New_Ctyp
);
634 Set_Has_Biased_Representation
(New_Ctyp
, True);
635 Set_Is_Itype
(New_Ctyp
, True);
636 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
638 Set_Component_Type
(Btype
, New_Ctyp
);
641 Set_Component_Size
(Btype
, Csize
);
642 Set_Has_Component_Size_Clause
(Btype
, True);
643 Set_Has_Non_Standard_Rep
(Btype
, True);
645 end Component_Size_Case
;
651 when Attribute_External_Tag
=> External_Tag
:
653 if not Is_Tagged_Type
(U_Ent
) then
654 Error_Msg_N
("should be a tagged type", Nam
);
657 Analyze_And_Resolve
(Expr
, Standard_String
);
659 if not Is_Static_Expression
(Expr
) then
661 ("static string required for tag name!", Nam
);
664 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
671 when Attribute_Input
=> Input
: declare
672 Subp
: Entity_Id
:= Empty
;
677 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
678 -- Return true if the entity is a function with an appropriate
679 -- profile for the Input attribute.
681 ----------------------
682 -- Has_Good_Profile --
683 ----------------------
685 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
687 Ok
: Boolean := False;
690 if Ekind
(Subp
) = E_Function
then
691 F
:= First_Formal
(Subp
);
693 if Present
(F
) and then No
(Next_Formal
(F
)) then
694 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
696 Designated_Type
(Etype
(F
)) =
697 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
699 Ok
:= Base_Type
(Etype
(Subp
)) = Base_Type
(Ent
);
705 end Has_Good_Profile
;
707 -- Start of processing for Input attribute definition
712 if not Is_Type
(U_Ent
) then
713 Error_Msg_N
("local name must be a subtype", Nam
);
717 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Input
);
720 and then Base_Type
(Etype
(Pnam
)) = Base_Type
(U_Ent
)
722 Error_Msg_Sloc
:= Sloc
(Pnam
);
723 Error_Msg_N
("input attribute already defined #", Nam
);
730 if Is_Entity_Name
(Expr
) then
731 if not Is_Overloaded
(Expr
) then
732 if Has_Good_Profile
(Entity
(Expr
)) then
733 Subp
:= Entity
(Expr
);
737 Get_First_Interp
(Expr
, I
, It
);
739 while Present
(It
.Nam
) loop
740 if Has_Good_Profile
(It
.Nam
) then
745 Get_Next_Interp
(I
, It
);
750 if Present
(Subp
) then
751 Set_Entity
(Expr
, Subp
);
752 Set_Etype
(Expr
, Etype
(Subp
));
753 New_Stream_Function
(N
, U_Ent
, Subp
, TSS_Stream_Input
);
755 Error_Msg_N
("incorrect expression for input attribute", Expr
);
764 -- Machine radix attribute definition clause
766 when Attribute_Machine_Radix
=> Machine_Radix
: declare
767 Radix
: constant Uint
:= Static_Integer
(Expr
);
770 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
771 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
773 elsif Has_Machine_Radix_Clause
(U_Ent
) then
774 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
775 Error_Msg_N
("machine radix clause previously given#", N
);
777 elsif Radix
/= No_Uint
then
778 Set_Has_Machine_Radix_Clause
(U_Ent
);
779 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
783 elsif Radix
= 10 then
784 Set_Machine_Radix_10
(U_Ent
);
786 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
795 -- Object_Size attribute definition clause
797 when Attribute_Object_Size
=> Object_Size
: declare
798 Size
: constant Uint
:= Static_Integer
(Expr
);
802 if not Is_Type
(U_Ent
) then
803 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
805 elsif Has_Object_Size_Clause
(U_Ent
) then
806 Error_Msg_N
("Object_Size already given for &", Nam
);
809 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
817 UI_Mod
(Size
, 64) /= 0
820 ("Object_Size must be 8, 16, 32, or multiple of 64",
824 Set_Esize
(U_Ent
, Size
);
825 Set_Has_Object_Size_Clause
(U_Ent
);
826 Alignment_Check_For_Esize_Change
(U_Ent
);
834 when Attribute_Output
=> Output
: declare
835 Subp
: Entity_Id
:= Empty
;
840 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
841 -- Return true if the entity is a procedure with an
842 -- appropriate profile for the output attribute.
844 ----------------------
845 -- Has_Good_Profile --
846 ----------------------
848 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
850 Ok
: Boolean := False;
853 if Ekind
(Subp
) = E_Procedure
then
854 F
:= First_Formal
(Subp
);
857 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
859 Designated_Type
(Etype
(F
)) =
860 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
864 and then Parameter_Mode
(F
) = E_In_Parameter
865 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
866 and then No
(Next_Formal
(F
));
872 end Has_Good_Profile
;
874 -- Start of processing for Output attribute definition
879 if not Is_Type
(U_Ent
) then
880 Error_Msg_N
("local name must be a subtype", Nam
);
884 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Output
);
888 Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
891 Error_Msg_Sloc
:= Sloc
(Pnam
);
892 Error_Msg_N
("output attribute already defined #", Nam
);
899 if Is_Entity_Name
(Expr
) then
900 if not Is_Overloaded
(Expr
) then
901 if Has_Good_Profile
(Entity
(Expr
)) then
902 Subp
:= Entity
(Expr
);
906 Get_First_Interp
(Expr
, I
, It
);
908 while Present
(It
.Nam
) loop
909 if Has_Good_Profile
(It
.Nam
) then
914 Get_Next_Interp
(I
, It
);
919 if Present
(Subp
) then
920 Set_Entity
(Expr
, Subp
);
921 Set_Etype
(Expr
, Etype
(Subp
));
922 New_Stream_Procedure
(N
, U_Ent
, Subp
, TSS_Stream_Output
);
924 Error_Msg_N
("incorrect expression for output attribute", Expr
);
933 when Attribute_Read
=> Read
: declare
934 Subp
: Entity_Id
:= Empty
;
939 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
940 -- Return true if the entity is a procedure with an appropriate
941 -- profile for the Read attribute.
943 ----------------------
944 -- Has_Good_Profile --
945 ----------------------
947 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
949 Ok
: Boolean := False;
952 if Ekind
(Subp
) = E_Procedure
then
953 F
:= First_Formal
(Subp
);
956 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
958 Designated_Type
(Etype
(F
)) =
959 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
963 and then Parameter_Mode
(F
) = E_Out_Parameter
964 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
965 and then No
(Next_Formal
(F
));
971 end Has_Good_Profile
;
973 -- Start of processing for Read attribute definition
978 if not Is_Type
(U_Ent
) then
979 Error_Msg_N
("local name must be a subtype", Nam
);
983 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Read
);
986 and then Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
989 Error_Msg_Sloc
:= Sloc
(Pnam
);
990 Error_Msg_N
("read attribute already defined #", Nam
);
997 if Is_Entity_Name
(Expr
) then
998 if not Is_Overloaded
(Expr
) then
999 if Has_Good_Profile
(Entity
(Expr
)) then
1000 Subp
:= Entity
(Expr
);
1004 Get_First_Interp
(Expr
, I
, It
);
1006 while Present
(It
.Nam
) loop
1007 if Has_Good_Profile
(It
.Nam
) then
1012 Get_Next_Interp
(I
, It
);
1017 if Present
(Subp
) then
1018 Set_Entity
(Expr
, Subp
);
1019 Set_Etype
(Expr
, Etype
(Subp
));
1020 New_Stream_Procedure
(N
, U_Ent
, Subp
, TSS_Stream_Read
, True);
1022 Error_Msg_N
("incorrect expression for read attribute", Expr
);
1031 -- Size attribute definition clause
1033 when Attribute_Size
=> Size
: declare
1034 Size
: constant Uint
:= Static_Integer
(Expr
);
1041 if Has_Size_Clause
(U_Ent
) then
1042 Error_Msg_N
("size already given for &", Nam
);
1044 elsif not Is_Type
(U_Ent
)
1045 and then Ekind
(U_Ent
) /= E_Variable
1046 and then Ekind
(U_Ent
) /= E_Constant
1048 Error_Msg_N
("size cannot be given for &", Nam
);
1050 elsif Is_Array_Type
(U_Ent
)
1051 and then not Is_Constrained
(U_Ent
)
1054 ("size cannot be given for unconstrained array", Nam
);
1056 elsif Size
/= No_Uint
then
1057 if Is_Type
(U_Ent
) then
1060 Etyp
:= Etype
(U_Ent
);
1063 -- Check size, note that Gigi is in charge of checking
1064 -- that the size of an array or record type is OK. Also
1065 -- we do not check the size in the ordinary fixed-point
1066 -- case, since it is too early to do so (there may be a
1067 -- subsequent small clause that affects the size). We can
1068 -- check the size if a small clause has already been given.
1070 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
1071 or else Has_Small_Clause
(U_Ent
)
1073 Check_Size
(Expr
, Etyp
, Size
, Biased
);
1074 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1077 -- For types set RM_Size and Esize if possible
1079 if Is_Type
(U_Ent
) then
1080 Set_RM_Size
(U_Ent
, Size
);
1082 -- For scalar types, increase Object_Size to power of 2,
1083 -- but not less than a storage unit in any case (i.e.,
1084 -- normally this means it will be byte addressable).
1086 if Is_Scalar_Type
(U_Ent
) then
1087 if Size
<= System_Storage_Unit
then
1088 Init_Esize
(U_Ent
, System_Storage_Unit
);
1089 elsif Size
<= 16 then
1090 Init_Esize
(U_Ent
, 16);
1091 elsif Size
<= 32 then
1092 Init_Esize
(U_Ent
, 32);
1094 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
1097 -- For all other types, object size = value size. The
1098 -- backend will adjust as needed.
1101 Set_Esize
(U_Ent
, Size
);
1104 Alignment_Check_For_Esize_Change
(U_Ent
);
1106 -- For objects, set Esize only
1109 if Is_Elementary_Type
(Etyp
) then
1110 if Size
/= System_Storage_Unit
1112 Size
/= System_Storage_Unit
* 2
1114 Size
/= System_Storage_Unit
* 4
1116 Size
/= System_Storage_Unit
* 8
1118 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
1120 ("size for primitive object must be a power of 2"
1121 & " and at least ^", N
);
1125 Set_Esize
(U_Ent
, Size
);
1128 Set_Has_Size_Clause
(U_Ent
);
1136 -- Small attribute definition clause
1138 when Attribute_Small
=> Small
: declare
1139 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
1143 Analyze_And_Resolve
(Expr
, Any_Real
);
1145 if Etype
(Expr
) = Any_Type
then
1148 elsif not Is_Static_Expression
(Expr
) then
1149 Flag_Non_Static_Expr
1150 ("small requires static expression!", Expr
);
1154 Small
:= Expr_Value_R
(Expr
);
1156 if Small
<= Ureal_0
then
1157 Error_Msg_N
("small value must be greater than zero", Expr
);
1163 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
1165 ("small requires an ordinary fixed point type", Nam
);
1167 elsif Has_Small_Clause
(U_Ent
) then
1168 Error_Msg_N
("small already given for &", Nam
);
1170 elsif Small
> Delta_Value
(U_Ent
) then
1172 ("small value must not be greater then delta value", Nam
);
1175 Set_Small_Value
(U_Ent
, Small
);
1176 Set_Small_Value
(Implicit_Base
, Small
);
1177 Set_Has_Small_Clause
(U_Ent
);
1178 Set_Has_Small_Clause
(Implicit_Base
);
1179 Set_Has_Non_Standard_Rep
(Implicit_Base
);
1187 -- Storage_Size attribute definition clause
1189 when Attribute_Storage_Size
=> Storage_Size
: declare
1190 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
1194 if Is_Task_Type
(U_Ent
) then
1195 Check_Restriction
(No_Obsolescent_Features
, N
);
1197 if Warn_On_Obsolescent_Feature
then
1199 ("storage size clause for task is an " &
1200 "obsolescent feature ('R'M 'J.9)?", N
);
1202 ("\use Storage_Size pragma instead?", N
);
1208 if not Is_Access_Type
(U_Ent
)
1209 and then Ekind
(U_Ent
) /= E_Task_Type
1211 Error_Msg_N
("storage size cannot be given for &", Nam
);
1213 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
1215 ("storage size cannot be given for a derived access type",
1218 elsif Has_Storage_Size_Clause
(Btype
) then
1219 Error_Msg_N
("storage size already given for &", Nam
);
1222 Analyze_And_Resolve
(Expr
, Any_Integer
);
1224 if Is_Access_Type
(U_Ent
) then
1226 if Present
(Associated_Storage_Pool
(U_Ent
)) then
1227 Error_Msg_N
("storage pool already given for &", Nam
);
1231 if Compile_Time_Known_Value
(Expr
)
1232 and then Expr_Value
(Expr
) = 0
1234 Set_No_Pool_Assigned
(Btype
);
1237 else -- Is_Task_Type (U_Ent)
1238 Sprag
:= Get_Rep_Pragma
(Btype
, Name_Storage_Size
);
1240 if Present
(Sprag
) then
1241 Error_Msg_Sloc
:= Sloc
(Sprag
);
1243 ("Storage_Size already specified#", Nam
);
1248 Set_Has_Storage_Size_Clause
(Btype
);
1256 -- Storage_Pool attribute definition clause
1258 when Attribute_Storage_Pool
=> Storage_Pool
: declare
1263 if Ekind
(U_Ent
) /= E_Access_Type
1264 and then Ekind
(U_Ent
) /= E_General_Access_Type
1267 "storage pool can only be given for access types", Nam
);
1270 elsif Is_Derived_Type
(U_Ent
) then
1272 ("storage pool cannot be given for a derived access type",
1275 elsif Has_Storage_Size_Clause
(U_Ent
) then
1276 Error_Msg_N
("storage size already given for &", Nam
);
1279 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
1280 Error_Msg_N
("storage pool already given for &", Nam
);
1285 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
1287 if Nkind
(Expr
) = N_Type_Conversion
then
1288 T
:= Etype
(Expression
(Expr
));
1293 -- The Stack_Bounded_Pool is used internally for implementing
1294 -- access types with a Storage_Size. Since it only work
1295 -- properly when used on one specific type, we need to check
1296 -- that it is not highjacked improperly:
1297 -- type T is access Integer;
1298 -- for T'Storage_Size use n;
1299 -- type Q is access Float;
1300 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
1302 if Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
) then
1303 Error_Msg_N
("non-sharable internal Pool", Expr
);
1307 -- If the argument is a name that is not an entity name, then
1308 -- we construct a renaming operation to define an entity of
1309 -- type storage pool.
1311 if not Is_Entity_Name
(Expr
)
1312 and then Is_Object_Reference
(Expr
)
1315 Make_Defining_Identifier
(Loc
,
1316 Chars
=> New_Internal_Name
('P'));
1319 Rnode
: constant Node_Id
:=
1320 Make_Object_Renaming_Declaration
(Loc
,
1321 Defining_Identifier
=> Pool
,
1323 New_Occurrence_Of
(Etype
(Expr
), Loc
),
1327 Insert_Before
(N
, Rnode
);
1329 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1332 elsif Is_Entity_Name
(Expr
) then
1333 Pool
:= Entity
(Expr
);
1335 -- If pool is a renamed object, get original one. This can
1336 -- happen with an explicit renaming, and within instances.
1338 while Present
(Renamed_Object
(Pool
))
1339 and then Is_Entity_Name
(Renamed_Object
(Pool
))
1341 Pool
:= Entity
(Renamed_Object
(Pool
));
1344 if Present
(Renamed_Object
(Pool
))
1345 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
1346 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
1348 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
1351 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1353 elsif Nkind
(Expr
) = N_Type_Conversion
1354 and then Is_Entity_Name
(Expression
(Expr
))
1355 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
1357 Pool
:= Entity
(Expression
(Expr
));
1358 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1361 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
1370 when Attribute_Stream_Size
=> Stream_Size
: declare
1371 Size
: constant Uint
:= Static_Integer
(Expr
);
1374 if Has_Stream_Size_Clause
(U_Ent
) then
1375 Error_Msg_N
("Stream_Size already given for &", Nam
);
1377 elsif Is_Elementary_Type
(U_Ent
) then
1378 if Size
/= System_Storage_Unit
1380 Size
/= System_Storage_Unit
* 2
1382 Size
/= System_Storage_Unit
* 4
1384 Size
/= System_Storage_Unit
* 8
1386 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
1388 ("stream size for elementary type must be a"
1389 & " power of 2 and at least ^", N
);
1391 elsif RM_Size
(U_Ent
) > Size
then
1392 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
1394 ("stream size for elementary type must be a"
1395 & " power of 2 and at least ^", N
);
1398 Set_Has_Stream_Size_Clause
(U_Ent
);
1401 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
1409 -- Value_Size attribute definition clause
1411 when Attribute_Value_Size
=> Value_Size
: declare
1412 Size
: constant Uint
:= Static_Integer
(Expr
);
1416 if not Is_Type
(U_Ent
) then
1417 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
1420 (Get_Attribute_Definition_Clause
1421 (U_Ent
, Attribute_Value_Size
))
1423 Error_Msg_N
("Value_Size already given for &", Nam
);
1426 if Is_Elementary_Type
(U_Ent
) then
1427 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
1428 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1431 Set_RM_Size
(U_Ent
, Size
);
1439 -- Write attribute definition clause
1440 -- check for class-wide case will be performed later
1442 when Attribute_Write
=> Write
: declare
1443 Subp
: Entity_Id
:= Empty
;
1448 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
1449 -- Return true if the entity is a procedure with an
1450 -- appropriate profile for the write attribute.
1452 ----------------------
1453 -- Has_Good_Profile --
1454 ----------------------
1456 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
1458 Ok
: Boolean := False;
1461 if Ekind
(Subp
) = E_Procedure
then
1462 F
:= First_Formal
(Subp
);
1465 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
1467 Designated_Type
(Etype
(F
)) =
1468 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
1472 and then Parameter_Mode
(F
) = E_In_Parameter
1473 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
1474 and then No
(Next_Formal
(F
));
1480 end Has_Good_Profile
;
1482 -- Start of processing for Write attribute definition
1487 if not Is_Type
(U_Ent
) then
1488 Error_Msg_N
("local name must be a subtype", Nam
);
1492 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Write
);
1495 and then Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
1498 Error_Msg_Sloc
:= Sloc
(Pnam
);
1499 Error_Msg_N
("write attribute already defined #", Nam
);
1505 if Is_Entity_Name
(Expr
) then
1506 if not Is_Overloaded
(Expr
) then
1507 if Has_Good_Profile
(Entity
(Expr
)) then
1508 Subp
:= Entity
(Expr
);
1512 Get_First_Interp
(Expr
, I
, It
);
1514 while Present
(It
.Nam
) loop
1515 if Has_Good_Profile
(It
.Nam
) then
1520 Get_Next_Interp
(I
, It
);
1525 if Present
(Subp
) then
1526 Set_Entity
(Expr
, Subp
);
1527 Set_Etype
(Expr
, Etype
(Subp
));
1528 New_Stream_Procedure
(N
, U_Ent
, Subp
, TSS_Stream_Write
);
1530 Error_Msg_N
("incorrect expression for write attribute", Expr
);
1535 -- All other attributes cannot be set
1539 ("attribute& cannot be set with definition clause", N
);
1542 -- The test for the type being frozen must be performed after
1543 -- any expression the clause has been analyzed since the expression
1544 -- itself might cause freezing that makes the clause illegal.
1546 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
1549 end Analyze_Attribute_Definition_Clause
;
1551 ----------------------------
1552 -- Analyze_Code_Statement --
1553 ----------------------------
1555 procedure Analyze_Code_Statement
(N
: Node_Id
) is
1556 HSS
: constant Node_Id
:= Parent
(N
);
1557 SBody
: constant Node_Id
:= Parent
(HSS
);
1558 Subp
: constant Entity_Id
:= Current_Scope
;
1565 -- Analyze and check we get right type, note that this implements the
1566 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1567 -- is the only way that Asm_Insn could possibly be visible.
1569 Analyze_And_Resolve
(Expression
(N
));
1571 if Etype
(Expression
(N
)) = Any_Type
then
1573 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
1574 Error_Msg_N
("incorrect type for code statement", N
);
1578 -- Make sure we appear in the handled statement sequence of a
1579 -- subprogram (RM 13.8(3)).
1581 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
1582 or else Nkind
(SBody
) /= N_Subprogram_Body
1585 ("code statement can only appear in body of subprogram", N
);
1589 -- Do remaining checks (RM 13.8(3)) if not already done
1591 if not Is_Machine_Code_Subprogram
(Subp
) then
1592 Set_Is_Machine_Code_Subprogram
(Subp
);
1594 -- No exception handlers allowed
1596 if Present
(Exception_Handlers
(HSS
)) then
1598 ("exception handlers not permitted in machine code subprogram",
1599 First
(Exception_Handlers
(HSS
)));
1602 -- No declarations other than use clauses and pragmas (we allow
1603 -- certain internally generated declarations as well).
1605 Decl
:= First
(Declarations
(SBody
));
1606 while Present
(Decl
) loop
1607 DeclO
:= Original_Node
(Decl
);
1608 if Comes_From_Source
(DeclO
)
1609 and then Nkind
(DeclO
) /= N_Pragma
1610 and then Nkind
(DeclO
) /= N_Use_Package_Clause
1611 and then Nkind
(DeclO
) /= N_Use_Type_Clause
1612 and then Nkind
(DeclO
) /= N_Implicit_Label_Declaration
1615 ("this declaration not allowed in machine code subprogram",
1622 -- No statements other than code statements, pragmas, and labels.
1623 -- Again we allow certain internally generated statements.
1625 Stmt
:= First
(Statements
(HSS
));
1626 while Present
(Stmt
) loop
1627 StmtO
:= Original_Node
(Stmt
);
1628 if Comes_From_Source
(StmtO
)
1629 and then Nkind
(StmtO
) /= N_Pragma
1630 and then Nkind
(StmtO
) /= N_Label
1631 and then Nkind
(StmtO
) /= N_Code_Statement
1634 ("this statement is not allowed in machine code subprogram",
1641 end Analyze_Code_Statement
;
1643 -----------------------------------------------
1644 -- Analyze_Enumeration_Representation_Clause --
1645 -----------------------------------------------
1647 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
1648 Ident
: constant Node_Id
:= Identifier
(N
);
1649 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
1650 Enumtype
: Entity_Id
;
1656 Err
: Boolean := False;
1658 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
1659 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
1664 -- First some basic error checks
1667 Enumtype
:= Entity
(Ident
);
1669 if Enumtype
= Any_Type
1670 or else Rep_Item_Too_Early
(Enumtype
, N
)
1674 Enumtype
:= Underlying_Type
(Enumtype
);
1677 if not Is_Enumeration_Type
(Enumtype
) then
1679 ("enumeration type required, found}",
1680 Ident
, First_Subtype
(Enumtype
));
1684 -- Ignore rep clause on generic actual type. This will already have
1685 -- been flagged on the template as an error, and this is the safest
1686 -- way to ensure we don't get a junk cascaded message in the instance.
1688 if Is_Generic_Actual_Type
(Enumtype
) then
1691 -- Type must be in current scope
1693 elsif Scope
(Enumtype
) /= Current_Scope
then
1694 Error_Msg_N
("type must be declared in this scope", Ident
);
1697 -- Type must be a first subtype
1699 elsif not Is_First_Subtype
(Enumtype
) then
1700 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
1703 -- Ignore duplicate rep clause
1705 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
1706 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
1709 -- Don't allow rep clause for standard [wide_[wide_]]character
1711 elsif Root_Type
(Enumtype
) = Standard_Character
1712 or else Root_Type
(Enumtype
) = Standard_Wide_Character
1713 or else Root_Type
(Enumtype
) = Standard_Wide_Wide_Character
1715 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
1718 -- All tests passed, so set rep clause in place
1721 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
1722 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
1725 -- Now we process the aggregate. Note that we don't use the normal
1726 -- aggregate code for this purpose, because we don't want any of the
1727 -- normal expansion activities, and a number of special semantic
1728 -- rules apply (including the component type being any integer type)
1730 -- Badent signals that we found some incorrect entries processing
1731 -- the list. The final checks for completeness and ordering are
1732 -- skipped in this case.
1734 Elit
:= First_Literal
(Enumtype
);
1736 -- First the positional entries if any
1738 if Present
(Expressions
(Aggr
)) then
1739 Expr
:= First
(Expressions
(Aggr
));
1740 while Present
(Expr
) loop
1742 Error_Msg_N
("too many entries in aggregate", Expr
);
1746 Val
:= Static_Integer
(Expr
);
1748 if Val
= No_Uint
then
1751 elsif Val
< Lo
or else Hi
< Val
then
1752 Error_Msg_N
("value outside permitted range", Expr
);
1756 Set_Enumeration_Rep
(Elit
, Val
);
1757 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
1763 -- Now process the named entries if present
1765 if Present
(Component_Associations
(Aggr
)) then
1766 Assoc
:= First
(Component_Associations
(Aggr
));
1767 while Present
(Assoc
) loop
1768 Choice
:= First
(Choices
(Assoc
));
1770 if Present
(Next
(Choice
)) then
1772 ("multiple choice not allowed here", Next
(Choice
));
1776 if Nkind
(Choice
) = N_Others_Choice
then
1777 Error_Msg_N
("others choice not allowed here", Choice
);
1780 elsif Nkind
(Choice
) = N_Range
then
1781 -- ??? should allow zero/one element range here
1782 Error_Msg_N
("range not allowed here", Choice
);
1786 Analyze_And_Resolve
(Choice
, Enumtype
);
1788 if Is_Entity_Name
(Choice
)
1789 and then Is_Type
(Entity
(Choice
))
1791 Error_Msg_N
("subtype name not allowed here", Choice
);
1793 -- ??? should allow static subtype with zero/one entry
1795 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
1796 if not Is_Static_Expression
(Choice
) then
1797 Flag_Non_Static_Expr
1798 ("non-static expression used for choice!", Choice
);
1802 Elit
:= Expr_Value_E
(Choice
);
1804 if Present
(Enumeration_Rep_Expr
(Elit
)) then
1805 Error_Msg_Sloc
:= Sloc
(Enumeration_Rep_Expr
(Elit
));
1807 ("representation for& previously given#",
1812 Set_Enumeration_Rep_Expr
(Elit
, Choice
);
1814 Expr
:= Expression
(Assoc
);
1815 Val
:= Static_Integer
(Expr
);
1817 if Val
= No_Uint
then
1820 elsif Val
< Lo
or else Hi
< Val
then
1821 Error_Msg_N
("value outside permitted range", Expr
);
1825 Set_Enumeration_Rep
(Elit
, Val
);
1834 -- Aggregate is fully processed. Now we check that a full set of
1835 -- representations was given, and that they are in range and in order.
1836 -- These checks are only done if no other errors occurred.
1842 Elit
:= First_Literal
(Enumtype
);
1843 while Present
(Elit
) loop
1844 if No
(Enumeration_Rep_Expr
(Elit
)) then
1845 Error_Msg_NE
("missing representation for&!", N
, Elit
);
1848 Val
:= Enumeration_Rep
(Elit
);
1850 if Min
= No_Uint
then
1854 if Val
/= No_Uint
then
1855 if Max
/= No_Uint
and then Val
<= Max
then
1857 ("enumeration value for& not ordered!",
1858 Enumeration_Rep_Expr
(Elit
), Elit
);
1864 -- If there is at least one literal whose representation
1865 -- is not equal to the Pos value, then note that this
1866 -- enumeration type has a non-standard representation.
1868 if Val
/= Enumeration_Pos
(Elit
) then
1869 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
1876 -- Now set proper size information
1879 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
1882 if Has_Size_Clause
(Enumtype
) then
1883 if Esize
(Enumtype
) >= Minsize
then
1888 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
1890 if Esize
(Enumtype
) < Minsize
then
1891 Error_Msg_N
("previously given size is too small", N
);
1894 Set_Has_Biased_Representation
(Enumtype
);
1899 Set_RM_Size
(Enumtype
, Minsize
);
1900 Set_Enum_Esize
(Enumtype
);
1903 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
1904 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
1905 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
1909 -- We repeat the too late test in case it froze itself!
1911 if Rep_Item_Too_Late
(Enumtype
, N
) then
1914 end Analyze_Enumeration_Representation_Clause
;
1916 ----------------------------
1917 -- Analyze_Free_Statement --
1918 ----------------------------
1920 procedure Analyze_Free_Statement
(N
: Node_Id
) is
1922 Analyze
(Expression
(N
));
1923 end Analyze_Free_Statement
;
1925 ------------------------------------------
1926 -- Analyze_Record_Representation_Clause --
1927 ------------------------------------------
1929 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
1930 Loc
: constant Source_Ptr
:= Sloc
(N
);
1931 Ident
: constant Node_Id
:= Identifier
(N
);
1932 Rectype
: Entity_Id
;
1938 Hbit
: Uint
:= Uint_0
;
1943 Max_Bit_So_Far
: Uint
;
1944 -- Records the maximum bit position so far. If all field positions
1945 -- are monotonically increasing, then we can skip the circuit for
1946 -- checking for overlap, since no overlap is possible.
1948 Overlap_Check_Required
: Boolean;
1949 -- Used to keep track of whether or not an overlap check is required
1951 Ccount
: Natural := 0;
1952 -- Number of component clauses in record rep clause
1956 Rectype
:= Entity
(Ident
);
1958 if Rectype
= Any_Type
1959 or else Rep_Item_Too_Early
(Rectype
, N
)
1963 Rectype
:= Underlying_Type
(Rectype
);
1966 -- First some basic error checks
1968 if not Is_Record_Type
(Rectype
) then
1970 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
1973 elsif Is_Unchecked_Union
(Rectype
) then
1975 ("record rep clause not allowed for Unchecked_Union", N
);
1977 elsif Scope
(Rectype
) /= Current_Scope
then
1978 Error_Msg_N
("type must be declared in this scope", N
);
1981 elsif not Is_First_Subtype
(Rectype
) then
1982 Error_Msg_N
("cannot give record rep clause for subtype", N
);
1985 elsif Has_Record_Rep_Clause
(Rectype
) then
1986 Error_Msg_N
("duplicate record rep clause ignored", N
);
1989 elsif Rep_Item_Too_Late
(Rectype
, N
) then
1993 if Present
(Mod_Clause
(N
)) then
1995 Loc
: constant Source_Ptr
:= Sloc
(N
);
1996 M
: constant Node_Id
:= Mod_Clause
(N
);
1997 P
: constant List_Id
:= Pragmas_Before
(M
);
2001 pragma Warnings
(Off
, Mod_Val
);
2004 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
2006 if Warn_On_Obsolescent_Feature
then
2008 ("mod clause is an obsolescent feature ('R'M 'J.8)?", N
);
2010 ("\use alignment attribute definition clause instead?", N
);
2017 -- In ASIS_Mode mode, expansion is disabled, but we must
2018 -- convert the Mod clause into an alignment clause anyway, so
2019 -- that the back-end can compute and back-annotate properly the
2020 -- size and alignment of types that may include this record.
2022 if Operating_Mode
= Check_Semantics
2026 Make_Attribute_Definition_Clause
(Loc
,
2027 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
2028 Chars
=> Name_Alignment
,
2029 Expression
=> Relocate_Node
(Expression
(M
)));
2031 Set_From_At_Mod
(AtM_Nod
);
2032 Insert_After
(N
, AtM_Nod
);
2033 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
2034 Set_Mod_Clause
(N
, Empty
);
2037 -- Get the alignment value to perform error checking
2039 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
2045 -- Clear any existing component clauses for the type (this happens
2046 -- with derived types, where we are now overriding the original)
2048 Fent
:= First_Entity
(Rectype
);
2051 while Present
(Comp
) loop
2052 if Ekind
(Comp
) = E_Component
2053 or else Ekind
(Comp
) = E_Discriminant
2055 Set_Component_Clause
(Comp
, Empty
);
2061 -- All done if no component clauses
2063 CC
:= First
(Component_Clauses
(N
));
2069 -- If a tag is present, then create a component clause that places
2070 -- it at the start of the record (otherwise gigi may place it after
2071 -- other fields that have rep clauses).
2073 if Nkind
(Fent
) = N_Defining_Identifier
2074 and then Chars
(Fent
) = Name_uTag
2076 Set_Component_Bit_Offset
(Fent
, Uint_0
);
2077 Set_Normalized_Position
(Fent
, Uint_0
);
2078 Set_Normalized_First_Bit
(Fent
, Uint_0
);
2079 Set_Normalized_Position_Max
(Fent
, Uint_0
);
2080 Init_Esize
(Fent
, System_Address_Size
);
2082 Set_Component_Clause
(Fent
,
2083 Make_Component_Clause
(Loc
,
2085 Make_Identifier
(Loc
,
2086 Chars
=> Name_uTag
),
2089 Make_Integer_Literal
(Loc
,
2093 Make_Integer_Literal
(Loc
,
2097 Make_Integer_Literal
(Loc
,
2098 UI_From_Int
(System_Address_Size
))));
2100 Ccount
:= Ccount
+ 1;
2103 -- A representation like this applies to the base type
2105 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
2106 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
2107 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
2109 Max_Bit_So_Far
:= Uint_Minus_1
;
2110 Overlap_Check_Required
:= False;
2112 -- Process the component clauses
2114 while Present
(CC
) loop
2116 -- If pragma, just analyze it
2118 if Nkind
(CC
) = N_Pragma
then
2121 -- Processing for real component clause
2124 Ccount
:= Ccount
+ 1;
2125 Posit
:= Static_Integer
(Position
(CC
));
2126 Fbit
:= Static_Integer
(First_Bit
(CC
));
2127 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2130 and then Fbit
/= No_Uint
2131 and then Lbit
/= No_Uint
2135 ("position cannot be negative", Position
(CC
));
2139 ("first bit cannot be negative", First_Bit
(CC
));
2141 -- Values look OK, so find the corresponding record component
2142 -- Even though the syntax allows an attribute reference for
2143 -- implementation-defined components, GNAT does not allow the
2144 -- tag to get an explicit position.
2146 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
2147 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
2148 Error_Msg_N
("position of tag cannot be specified", CC
);
2150 Error_Msg_N
("illegal component name", CC
);
2154 Comp
:= First_Entity
(Rectype
);
2155 while Present
(Comp
) loop
2156 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
2162 -- Maybe component of base type that is absent from
2163 -- statically constrained first subtype.
2165 Comp
:= First_Entity
(Base_Type
(Rectype
));
2166 while Present
(Comp
) loop
2167 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
2174 ("component clause is for non-existent field", CC
);
2176 elsif Present
(Component_Clause
(Comp
)) then
2177 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
2179 ("component clause previously given#", CC
);
2182 -- Update Fbit and Lbit to the actual bit number
2184 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
2185 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
2187 if Fbit
<= Max_Bit_So_Far
then
2188 Overlap_Check_Required
:= True;
2190 Max_Bit_So_Far
:= Lbit
;
2193 if Has_Size_Clause
(Rectype
)
2194 and then Esize
(Rectype
) <= Lbit
2197 ("bit number out of range of specified size",
2200 Set_Component_Clause
(Comp
, CC
);
2201 Set_Component_Bit_Offset
(Comp
, Fbit
);
2202 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
2203 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
2204 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
2206 Set_Normalized_Position_Max
2207 (Fent
, Normalized_Position
(Fent
));
2209 if Is_Tagged_Type
(Rectype
)
2210 and then Fbit
< System_Address_Size
2213 ("component overlaps tag field of&",
2217 -- This information is also set in the corresponding
2218 -- component of the base type, found by accessing the
2219 -- Original_Record_Component link if it is present.
2221 Ocomp
:= Original_Record_Component
(Comp
);
2228 (Component_Name
(CC
),
2233 Set_Has_Biased_Representation
(Comp
, Biased
);
2235 if Present
(Ocomp
) then
2236 Set_Component_Clause
(Ocomp
, CC
);
2237 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
2238 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
2239 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
2240 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
2242 Set_Normalized_Position_Max
2243 (Ocomp
, Normalized_Position
(Ocomp
));
2245 Set_Has_Biased_Representation
2246 (Ocomp
, Has_Biased_Representation
(Comp
));
2249 if Esize
(Comp
) < 0 then
2250 Error_Msg_N
("component size is negative", CC
);
2261 -- Now that we have processed all the component clauses, check for
2262 -- overlap. We have to leave this till last, since the components
2263 -- can appear in any arbitrary order in the representation clause.
2265 -- We do not need this check if all specified ranges were monotonic,
2266 -- as recorded by Overlap_Check_Required being False at this stage.
2268 -- This first section checks if there are any overlapping entries
2269 -- at all. It does this by sorting all entries and then seeing if
2270 -- there are any overlaps. If there are none, then that is decisive,
2271 -- but if there are overlaps, they may still be OK (they may result
2272 -- from fields in different variants).
2274 if Overlap_Check_Required
then
2275 Overlap_Check1
: declare
2277 OC_Fbit
: array (0 .. Ccount
) of Uint
;
2278 -- First-bit values for component clauses, the value is the
2279 -- offset of the first bit of the field from start of record.
2280 -- The zero entry is for use in sorting.
2282 OC_Lbit
: array (0 .. Ccount
) of Uint
;
2283 -- Last-bit values for component clauses, the value is the
2284 -- offset of the last bit of the field from start of record.
2285 -- The zero entry is for use in sorting.
2287 OC_Count
: Natural := 0;
2288 -- Count of entries in OC_Fbit and OC_Lbit
2290 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
2291 -- Compare routine for Sort (See GNAT.Heap_Sort_A)
2293 procedure OC_Move
(From
: Natural; To
: Natural);
2294 -- Move routine for Sort (see GNAT.Heap_Sort_A)
2296 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
2298 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
2301 procedure OC_Move
(From
: Natural; To
: Natural) is
2303 OC_Fbit
(To
) := OC_Fbit
(From
);
2304 OC_Lbit
(To
) := OC_Lbit
(From
);
2308 CC
:= First
(Component_Clauses
(N
));
2309 while Present
(CC
) loop
2310 if Nkind
(CC
) /= N_Pragma
then
2311 Posit
:= Static_Integer
(Position
(CC
));
2312 Fbit
:= Static_Integer
(First_Bit
(CC
));
2313 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2316 and then Fbit
/= No_Uint
2317 and then Lbit
/= No_Uint
2319 OC_Count
:= OC_Count
+ 1;
2320 Posit
:= Posit
* SSU
;
2321 OC_Fbit
(OC_Count
) := Fbit
+ Posit
;
2322 OC_Lbit
(OC_Count
) := Lbit
+ Posit
;
2331 OC_Move
'Unrestricted_Access,
2332 OC_Lt
'Unrestricted_Access);
2334 Overlap_Check_Required
:= False;
2335 for J
in 1 .. OC_Count
- 1 loop
2336 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
2337 Overlap_Check_Required
:= True;
2344 -- If Overlap_Check_Required is still True, then we have to do
2345 -- the full scale overlap check, since we have at least two fields
2346 -- that do overlap, and we need to know if that is OK since they
2347 -- are in the same variant, or whether we have a definite problem
2349 if Overlap_Check_Required
then
2350 Overlap_Check2
: declare
2351 C1_Ent
, C2_Ent
: Entity_Id
;
2352 -- Entities of components being checked for overlap
2355 -- Component_List node whose Component_Items are being checked
2358 -- Component declaration for component being checked
2361 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
2363 -- Loop through all components in record. For each component check
2364 -- for overlap with any of the preceding elements on the component
2365 -- list containing the component, and also, if the component is in
2366 -- a variant, check against components outside the case structure.
2367 -- This latter test is repeated recursively up the variant tree.
2369 Main_Component_Loop
: while Present
(C1_Ent
) loop
2370 if Ekind
(C1_Ent
) /= E_Component
2371 and then Ekind
(C1_Ent
) /= E_Discriminant
2373 goto Continue_Main_Component_Loop
;
2376 -- Skip overlap check if entity has no declaration node. This
2377 -- happens with discriminants in constrained derived types.
2378 -- Probably we are missing some checks as a result, but that
2379 -- does not seem terribly serious ???
2381 if No
(Declaration_Node
(C1_Ent
)) then
2382 goto Continue_Main_Component_Loop
;
2385 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
2387 -- Loop through component lists that need checking. Check the
2388 -- current component list and all lists in variants above us.
2390 Component_List_Loop
: loop
2392 -- If derived type definition, go to full declaration
2393 -- If at outer level, check discriminants if there are any
2395 if Nkind
(Clist
) = N_Derived_Type_Definition
then
2396 Clist
:= Parent
(Clist
);
2399 -- Outer level of record definition, check discriminants
2401 if Nkind
(Clist
) = N_Full_Type_Declaration
2402 or else Nkind
(Clist
) = N_Private_Type_Declaration
2404 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
2406 First_Discriminant
(Defining_Identifier
(Clist
));
2408 while Present
(C2_Ent
) loop
2409 exit when C1_Ent
= C2_Ent
;
2410 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2411 Next_Discriminant
(C2_Ent
);
2415 -- Record extension case
2417 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
2420 -- Otherwise check one component list
2423 Citem
:= First
(Component_Items
(Clist
));
2425 while Present
(Citem
) loop
2426 if Nkind
(Citem
) = N_Component_Declaration
then
2427 C2_Ent
:= Defining_Identifier
(Citem
);
2428 exit when C1_Ent
= C2_Ent
;
2429 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2436 -- Check for variants above us (the parent of the Clist can
2437 -- be a variant, in which case its parent is a variant part,
2438 -- and the parent of the variant part is a component list
2439 -- whose components must all be checked against the current
2440 -- component for overlap.
2442 if Nkind
(Parent
(Clist
)) = N_Variant
then
2443 Clist
:= Parent
(Parent
(Parent
(Clist
)));
2445 -- Check for possible discriminant part in record, this is
2446 -- treated essentially as another level in the recursion.
2447 -- For this case we have the parent of the component list
2448 -- is the record definition, and its parent is the full
2449 -- type declaration which contains the discriminant
2452 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
2453 Clist
:= Parent
(Parent
((Clist
)));
2455 -- If neither of these two cases, we are at the top of
2459 exit Component_List_Loop
;
2461 end loop Component_List_Loop
;
2463 <<Continue_Main_Component_Loop
>>
2464 Next_Entity
(C1_Ent
);
2466 end loop Main_Component_Loop
;
2470 -- For records that have component clauses for all components, and
2471 -- whose size is less than or equal to 32, we need to know the size
2472 -- in the front end to activate possible packed array processing
2473 -- where the component type is a record.
2475 -- At this stage Hbit + 1 represents the first unused bit from all
2476 -- the component clauses processed, so if the component clauses are
2477 -- complete, then this is the length of the record.
2479 -- For records longer than System.Storage_Unit, and for those where
2480 -- not all components have component clauses, the back end determines
2481 -- the length (it may for example be appopriate to round up the size
2482 -- to some convenient boundary, based on alignment considerations etc).
2484 if Unknown_RM_Size
(Rectype
)
2485 and then Hbit
+ 1 <= 32
2487 -- Nothing to do if at least one component with no component clause
2489 Comp
:= First_Entity
(Rectype
);
2490 while Present
(Comp
) loop
2491 if Ekind
(Comp
) = E_Component
2492 or else Ekind
(Comp
) = E_Discriminant
2494 if No
(Component_Clause
(Comp
)) then
2502 -- If we fall out of loop, all components have component clauses
2503 -- and so we can set the size to the maximum value.
2505 Set_RM_Size
(Rectype
, Hbit
+ 1);
2507 end Analyze_Record_Representation_Clause
;
2509 -----------------------------
2510 -- Check_Component_Overlap --
2511 -----------------------------
2513 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
2515 if Present
(Component_Clause
(C1_Ent
))
2516 and then Present
(Component_Clause
(C2_Ent
))
2518 -- Exclude odd case where we have two tag fields in the same
2519 -- record, both at location zero. This seems a bit strange,
2520 -- but it seems to happen in some circumstances ???
2522 if Chars
(C1_Ent
) = Name_uTag
2523 and then Chars
(C2_Ent
) = Name_uTag
2528 -- Here we check if the two fields overlap
2531 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
2532 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
2533 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
2534 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
2537 if E2
<= S1
or else E1
<= S2
then
2541 Component_Name
(Component_Clause
(C2_Ent
));
2542 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
2544 Component_Name
(Component_Clause
(C1_Ent
));
2546 ("component& overlaps & #",
2547 Component_Name
(Component_Clause
(C1_Ent
)));
2551 end Check_Component_Overlap
;
2553 -----------------------------------
2554 -- Check_Constant_Address_Clause --
2555 -----------------------------------
2557 procedure Check_Constant_Address_Clause
2561 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
2562 -- Checks that the given node N represents a name whose 'Address
2563 -- is constant (in the same sense as OK_Constant_Address_Clause,
2564 -- i.e. the address value is the same at the point of declaration
2565 -- of U_Ent and at the time of elaboration of the address clause.
2567 procedure Check_Expr_Constants
(Nod
: Node_Id
);
2568 -- Checks that Nod meets the requirements for a constant address
2569 -- clause in the sense of the enclosing procedure.
2571 procedure Check_List_Constants
(Lst
: List_Id
);
2572 -- Check that all elements of list Lst meet the requirements for a
2573 -- constant address clause in the sense of the enclosing procedure.
2575 -------------------------------
2576 -- Check_At_Constant_Address --
2577 -------------------------------
2579 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
2581 if Is_Entity_Name
(Nod
) then
2582 if Present
(Address_Clause
(Entity
((Nod
)))) then
2584 ("invalid address clause for initialized object &!",
2587 ("address for& cannot" &
2588 " depend on another address clause! ('R'M 13.1(22))!",
2591 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
2592 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
2595 ("invalid address clause for initialized object &!",
2597 Error_Msg_Name_1
:= Chars
(Entity
(Nod
));
2598 Error_Msg_Name_2
:= Chars
(U_Ent
);
2600 ("\% must be defined before % ('R'M 13.1(22))!",
2604 elsif Nkind
(Nod
) = N_Selected_Component
then
2606 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
2609 if (Is_Record_Type
(T
)
2610 and then Has_Discriminants
(T
))
2613 and then Is_Record_Type
(Designated_Type
(T
))
2614 and then Has_Discriminants
(Designated_Type
(T
)))
2617 ("invalid address clause for initialized object &!",
2620 ("\address cannot depend on component" &
2621 " of discriminated record ('R'M 13.1(22))!",
2624 Check_At_Constant_Address
(Prefix
(Nod
));
2628 elsif Nkind
(Nod
) = N_Indexed_Component
then
2629 Check_At_Constant_Address
(Prefix
(Nod
));
2630 Check_List_Constants
(Expressions
(Nod
));
2633 Check_Expr_Constants
(Nod
);
2635 end Check_At_Constant_Address
;
2637 --------------------------
2638 -- Check_Expr_Constants --
2639 --------------------------
2641 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
2642 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
2643 Ent
: Entity_Id
:= Empty
;
2646 if Nkind
(Nod
) in N_Has_Etype
2647 and then Etype
(Nod
) = Any_Type
2653 when N_Empty | N_Error
=>
2656 when N_Identifier | N_Expanded_Name
=>
2657 Ent
:= Entity
(Nod
);
2659 -- We need to look at the original node if it is different
2660 -- from the node, since we may have rewritten things and
2661 -- substituted an identifier representing the rewrite.
2663 if Original_Node
(Nod
) /= Nod
then
2664 Check_Expr_Constants
(Original_Node
(Nod
));
2666 -- If the node is an object declaration without initial
2667 -- value, some code has been expanded, and the expression
2668 -- is not constant, even if the constituents might be
2669 -- acceptable, as in A'Address + offset.
2671 if Ekind
(Ent
) = E_Variable
2672 and then Nkind
(Declaration_Node
(Ent
))
2673 = N_Object_Declaration
2675 No
(Expression
(Declaration_Node
(Ent
)))
2678 ("invalid address clause for initialized object &!",
2681 -- If entity is constant, it may be the result of expanding
2682 -- a check. We must verify that its declaration appears
2683 -- before the object in question, else we also reject the
2686 elsif Ekind
(Ent
) = E_Constant
2687 and then In_Same_Source_Unit
(Ent
, U_Ent
)
2688 and then Sloc
(Ent
) > Loc_U_Ent
2691 ("invalid address clause for initialized object &!",
2698 -- Otherwise look at the identifier and see if it is OK
2700 if Ekind
(Ent
) = E_Named_Integer
2702 Ekind
(Ent
) = E_Named_Real
2709 Ekind
(Ent
) = E_Constant
2711 Ekind
(Ent
) = E_In_Parameter
2713 -- This is the case where we must have Ent defined
2714 -- before U_Ent. Clearly if they are in different
2715 -- units this requirement is met since the unit
2716 -- containing Ent is already processed.
2718 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
2721 -- Otherwise location of Ent must be before the
2722 -- location of U_Ent, that's what prior defined means.
2724 elsif Sloc
(Ent
) < Loc_U_Ent
then
2729 ("invalid address clause for initialized object &!",
2731 Error_Msg_Name_1
:= Chars
(Ent
);
2732 Error_Msg_Name_2
:= Chars
(U_Ent
);
2734 ("\% must be defined before % ('R'M 13.1(22))!",
2738 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2739 Check_Expr_Constants
(Original_Node
(Nod
));
2743 ("invalid address clause for initialized object &!",
2746 if Comes_From_Source
(Ent
) then
2747 Error_Msg_Name_1
:= Chars
(Ent
);
2749 ("\reference to variable% not allowed"
2750 & " ('R'M 13.1(22))!", Nod
);
2753 ("non-static expression not allowed"
2754 & " ('R'M 13.1(22))!", Nod
);
2758 when N_Integer_Literal
=>
2760 -- If this is a rewritten unchecked conversion, in a system
2761 -- where Address is an integer type, always use the base type
2762 -- for a literal value. This is user-friendly and prevents
2763 -- order-of-elaboration issues with instances of unchecked
2766 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2767 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2770 when N_Real_Literal |
2772 N_Character_Literal
=>
2776 Check_Expr_Constants
(Low_Bound
(Nod
));
2777 Check_Expr_Constants
(High_Bound
(Nod
));
2779 when N_Explicit_Dereference
=>
2780 Check_Expr_Constants
(Prefix
(Nod
));
2782 when N_Indexed_Component
=>
2783 Check_Expr_Constants
(Prefix
(Nod
));
2784 Check_List_Constants
(Expressions
(Nod
));
2787 Check_Expr_Constants
(Prefix
(Nod
));
2788 Check_Expr_Constants
(Discrete_Range
(Nod
));
2790 when N_Selected_Component
=>
2791 Check_Expr_Constants
(Prefix
(Nod
));
2793 when N_Attribute_Reference
=>
2795 if Attribute_Name
(Nod
) = Name_Address
2797 Attribute_Name
(Nod
) = Name_Access
2799 Attribute_Name
(Nod
) = Name_Unchecked_Access
2801 Attribute_Name
(Nod
) = Name_Unrestricted_Access
2803 Check_At_Constant_Address
(Prefix
(Nod
));
2806 Check_Expr_Constants
(Prefix
(Nod
));
2807 Check_List_Constants
(Expressions
(Nod
));
2811 Check_List_Constants
(Component_Associations
(Nod
));
2812 Check_List_Constants
(Expressions
(Nod
));
2814 when N_Component_Association
=>
2815 Check_Expr_Constants
(Expression
(Nod
));
2817 when N_Extension_Aggregate
=>
2818 Check_Expr_Constants
(Ancestor_Part
(Nod
));
2819 Check_List_Constants
(Component_Associations
(Nod
));
2820 Check_List_Constants
(Expressions
(Nod
));
2825 when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In
=>
2826 Check_Expr_Constants
(Left_Opnd
(Nod
));
2827 Check_Expr_Constants
(Right_Opnd
(Nod
));
2830 Check_Expr_Constants
(Right_Opnd
(Nod
));
2832 when N_Type_Conversion |
2833 N_Qualified_Expression |
2835 Check_Expr_Constants
(Expression
(Nod
));
2837 when N_Unchecked_Type_Conversion
=>
2838 Check_Expr_Constants
(Expression
(Nod
));
2840 -- If this is a rewritten unchecked conversion, subtypes
2841 -- in this node are those created within the instance.
2842 -- To avoid order of elaboration issues, replace them
2843 -- with their base types. Note that address clauses can
2844 -- cause order of elaboration problems because they are
2845 -- elaborated by the back-end at the point of definition,
2846 -- and may mention entities declared in between (as long
2847 -- as everything is static). It is user-friendly to allow
2848 -- unchecked conversions in this context.
2850 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2851 Set_Etype
(Expression
(Nod
),
2852 Base_Type
(Etype
(Expression
(Nod
))));
2853 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2856 when N_Function_Call
=>
2857 if not Is_Pure
(Entity
(Name
(Nod
))) then
2859 ("invalid address clause for initialized object &!",
2863 ("\function & is not pure ('R'M 13.1(22))!",
2864 Nod
, Entity
(Name
(Nod
)));
2867 Check_List_Constants
(Parameter_Associations
(Nod
));
2870 when N_Parameter_Association
=>
2871 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
2875 ("invalid address clause for initialized object &!",
2878 ("\must be constant defined before& ('R'M 13.1(22))!",
2881 end Check_Expr_Constants
;
2883 --------------------------
2884 -- Check_List_Constants --
2885 --------------------------
2887 procedure Check_List_Constants
(Lst
: List_Id
) is
2891 if Present
(Lst
) then
2892 Nod1
:= First
(Lst
);
2893 while Present
(Nod1
) loop
2894 Check_Expr_Constants
(Nod1
);
2898 end Check_List_Constants
;
2900 -- Start of processing for Check_Constant_Address_Clause
2903 Check_Expr_Constants
(Expr
);
2904 end Check_Constant_Address_Clause
;
2910 procedure Check_Size
2914 Biased
: out Boolean)
2916 UT
: constant Entity_Id
:= Underlying_Type
(T
);
2922 -- Dismiss cases for generic types or types with previous errors
2925 or else UT
= Any_Type
2926 or else Is_Generic_Type
(UT
)
2927 or else Is_Generic_Type
(Root_Type
(UT
))
2931 -- Check case of bit packed array
2933 elsif Is_Array_Type
(UT
)
2934 and then Known_Static_Component_Size
(UT
)
2935 and then Is_Bit_Packed_Array
(UT
)
2943 Asiz
:= Component_Size
(UT
);
2944 Indx
:= First_Index
(UT
);
2946 Ityp
:= Etype
(Indx
);
2948 -- If non-static bound, then we are not in the business of
2949 -- trying to check the length, and indeed an error will be
2950 -- issued elsewhere, since sizes of non-static array types
2951 -- cannot be set implicitly or explicitly.
2953 if not Is_Static_Subtype
(Ityp
) then
2957 -- Otherwise accumulate next dimension
2959 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
2960 Expr_Value
(Type_Low_Bound
(Ityp
)) +
2964 exit when No
(Indx
);
2970 Error_Msg_Uint_1
:= Asiz
;
2972 ("size for& too small, minimum allowed is ^", N
, T
);
2973 Set_Esize
(T
, Asiz
);
2974 Set_RM_Size
(T
, Asiz
);
2978 -- All other composite types are ignored
2980 elsif Is_Composite_Type
(UT
) then
2983 -- For fixed-point types, don't check minimum if type is not frozen,
2984 -- since we don't know all the characteristics of the type that can
2985 -- affect the size (e.g. a specified small) till freeze time.
2987 elsif Is_Fixed_Point_Type
(UT
)
2988 and then not Is_Frozen
(UT
)
2992 -- Cases for which a minimum check is required
2995 -- Ignore if specified size is correct for the type
2997 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
3001 -- Otherwise get minimum size
3003 M
:= UI_From_Int
(Minimum_Size
(UT
));
3007 -- Size is less than minimum size, but one possibility remains
3008 -- that we can manage with the new size if we bias the type
3010 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
3013 Error_Msg_Uint_1
:= M
;
3015 ("size for& too small, minimum allowed is ^", N
, T
);
3025 -------------------------
3026 -- Get_Alignment_Value --
3027 -------------------------
3029 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
3030 Align
: constant Uint
:= Static_Integer
(Expr
);
3033 if Align
= No_Uint
then
3036 elsif Align
<= 0 then
3037 Error_Msg_N
("alignment value must be positive", Expr
);
3041 for J
in Int
range 0 .. 64 loop
3043 M
: constant Uint
:= Uint_2
** J
;
3046 exit when M
= Align
;
3050 ("alignment value must be power of 2", Expr
);
3058 end Get_Alignment_Value
;
3064 procedure Initialize
is
3066 Unchecked_Conversions
.Init
;
3069 -------------------------
3070 -- Is_Operational_Item --
3071 -------------------------
3073 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
3075 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
3079 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
3082 return Id
= Attribute_Input
3083 or else Id
= Attribute_Output
3084 or else Id
= Attribute_Read
3085 or else Id
= Attribute_Write
3086 or else Id
= Attribute_External_Tag
;
3089 end Is_Operational_Item
;
3091 --------------------------------------
3092 -- Mark_Aliased_Address_As_Volatile --
3093 --------------------------------------
3095 procedure Mark_Aliased_Address_As_Volatile
(N
: Node_Id
) is
3096 Ent
: constant Entity_Id
:= Address_Aliased_Entity
(N
);
3099 if Present
(Ent
) then
3100 Set_Treat_As_Volatile
(Ent
);
3102 end Mark_Aliased_Address_As_Volatile
;
3108 function Minimum_Size
3110 Biased
: Boolean := False) return Nat
3112 Lo
: Uint
:= No_Uint
;
3113 Hi
: Uint
:= No_Uint
;
3114 LoR
: Ureal
:= No_Ureal
;
3115 HiR
: Ureal
:= No_Ureal
;
3116 LoSet
: Boolean := False;
3117 HiSet
: Boolean := False;
3121 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
3124 -- If bad type, return 0
3126 if T
= Any_Type
then
3129 -- For generic types, just return zero. There cannot be any legitimate
3130 -- need to know such a size, but this routine may be called with a
3131 -- generic type as part of normal processing.
3133 elsif Is_Generic_Type
(R_Typ
)
3134 or else R_Typ
= Any_Type
3138 -- Access types. Normally an access type cannot have a size smaller
3139 -- than the size of System.Address. The exception is on VMS, where
3140 -- we have short and long addresses, and it is possible for an access
3141 -- type to have a short address size (and thus be less than the size
3142 -- of System.Address itself). We simply skip the check for VMS, and
3143 -- leave the back end to do the check.
3145 elsif Is_Access_Type
(T
) then
3146 if OpenVMS_On_Target
then
3149 return System_Address_Size
;
3152 -- Floating-point types
3154 elsif Is_Floating_Point_Type
(T
) then
3155 return UI_To_Int
(Esize
(R_Typ
));
3159 elsif Is_Discrete_Type
(T
) then
3161 -- The following loop is looking for the nearest compile time
3162 -- known bounds following the ancestor subtype chain. The idea
3163 -- is to find the most restrictive known bounds information.
3167 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
3172 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
3173 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
3180 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
3181 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
3187 Ancest
:= Ancestor_Subtype
(Ancest
);
3190 Ancest
:= Base_Type
(T
);
3192 if Is_Generic_Type
(Ancest
) then
3198 -- Fixed-point types. We can't simply use Expr_Value to get the
3199 -- Corresponding_Integer_Value values of the bounds, since these
3200 -- do not get set till the type is frozen, and this routine can
3201 -- be called before the type is frozen. Similarly the test for
3202 -- bounds being static needs to include the case where we have
3203 -- unanalyzed real literals for the same reason.
3205 elsif Is_Fixed_Point_Type
(T
) then
3207 -- The following loop is looking for the nearest compile time
3208 -- known bounds following the ancestor subtype chain. The idea
3209 -- is to find the most restrictive known bounds information.
3213 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
3218 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
3219 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
3221 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
3228 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
3229 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
3231 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
3237 Ancest
:= Ancestor_Subtype
(Ancest
);
3240 Ancest
:= Base_Type
(T
);
3242 if Is_Generic_Type
(Ancest
) then
3248 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
3249 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
3251 -- No other types allowed
3254 raise Program_Error
;
3257 -- Fall through with Hi and Lo set. Deal with biased case
3259 if (Biased
and then not Is_Fixed_Point_Type
(T
))
3260 or else Has_Biased_Representation
(T
)
3266 -- Signed case. Note that we consider types like range 1 .. -1 to be
3267 -- signed for the purpose of computing the size, since the bounds
3268 -- have to be accomodated in the base type.
3270 if Lo
< 0 or else Hi
< 0 then
3274 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3275 -- Note that we accommodate the case where the bounds cross. This
3276 -- can happen either because of the way the bounds are declared
3277 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3291 -- If both bounds are positive, make sure that both are represen-
3292 -- table in the case where the bounds are crossed. This can happen
3293 -- either because of the way the bounds are declared, or because of
3294 -- the algorithm in Freeze_Fixed_Point_Type.
3300 -- S = size, (can accommodate 0 .. (2**size - 1))
3303 while Hi
>= Uint_2
** S
loop
3311 -------------------------
3312 -- New_Stream_Function --
3313 -------------------------
3315 procedure New_Stream_Function
3319 Nam
: TSS_Name_Type
)
3321 Loc
: constant Source_Ptr
:= Sloc
(N
);
3322 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3323 Subp_Id
: Entity_Id
;
3324 Subp_Decl
: Node_Id
;
3328 function Build_Spec
return Node_Id
;
3329 -- Used for declaration and renaming declaration, so that this is
3330 -- treated as a renaming_as_body.
3336 function Build_Spec
return Node_Id
is
3338 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3341 Make_Function_Specification
(Loc
,
3342 Defining_Unit_Name
=> Subp_Id
,
3343 Parameter_Specifications
=>
3345 Make_Parameter_Specification
(Loc
,
3346 Defining_Identifier
=>
3347 Make_Defining_Identifier
(Loc
, Name_S
),
3349 Make_Access_Definition
(Loc
,
3352 Designated_Type
(Etype
(F
)), Loc
)))),
3355 New_Reference_To
(Etyp
, Loc
));
3358 -- Start of processing for New_Stream_Function
3361 F
:= First_Formal
(Subp
);
3362 Etyp
:= Etype
(Subp
);
3364 if not Is_Tagged_Type
(Ent
) then
3366 Make_Subprogram_Declaration
(Loc
,
3367 Specification
=> Build_Spec
);
3368 Insert_Action
(N
, Subp_Decl
);
3372 Make_Subprogram_Renaming_Declaration
(Loc
,
3373 Specification
=> Build_Spec
,
3374 Name
=> New_Reference_To
(Subp
, Loc
));
3376 if Is_Tagged_Type
(Ent
) then
3377 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3379 Insert_Action
(N
, Subp_Decl
);
3380 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3382 end New_Stream_Function
;
3384 --------------------------
3385 -- New_Stream_Procedure --
3386 --------------------------
3388 procedure New_Stream_Procedure
3392 Nam
: TSS_Name_Type
;
3393 Out_P
: Boolean := False)
3395 Loc
: constant Source_Ptr
:= Sloc
(N
);
3396 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3397 Subp_Id
: Entity_Id
;
3398 Subp_Decl
: Node_Id
;
3402 function Build_Spec
return Node_Id
;
3403 -- Used for declaration and renaming declaration, so that this is
3404 -- treated as a renaming_as_body.
3410 function Build_Spec
return Node_Id
is
3412 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3415 Make_Procedure_Specification
(Loc
,
3416 Defining_Unit_Name
=> Subp_Id
,
3417 Parameter_Specifications
=>
3419 Make_Parameter_Specification
(Loc
,
3420 Defining_Identifier
=>
3421 Make_Defining_Identifier
(Loc
, Name_S
),
3423 Make_Access_Definition
(Loc
,
3426 Designated_Type
(Etype
(F
)), Loc
))),
3428 Make_Parameter_Specification
(Loc
,
3429 Defining_Identifier
=>
3430 Make_Defining_Identifier
(Loc
, Name_V
),
3431 Out_Present
=> Out_P
,
3433 New_Reference_To
(Etyp
, Loc
))));
3436 -- Start of processing for New_Stream_Procedure
3439 F
:= First_Formal
(Subp
);
3440 Etyp
:= Etype
(Next_Formal
(F
));
3442 if not Is_Tagged_Type
(Ent
) then
3444 Make_Subprogram_Declaration
(Loc
,
3445 Specification
=> Build_Spec
);
3446 Insert_Action
(N
, Subp_Decl
);
3450 Make_Subprogram_Renaming_Declaration
(Loc
,
3451 Specification
=> Build_Spec
,
3452 Name
=> New_Reference_To
(Subp
, Loc
));
3454 if Is_Tagged_Type
(Ent
) then
3455 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3457 Insert_Action
(N
, Subp_Decl
);
3458 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3460 end New_Stream_Procedure
;
3462 ------------------------
3463 -- Rep_Item_Too_Early --
3464 ------------------------
3466 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
3468 -- Cannot apply rep items that are not operational items
3471 if Is_Operational_Item
(N
) then
3475 and then Is_Generic_Type
(Root_Type
(T
))
3478 ("representation item not allowed for generic type", N
);
3482 -- Otherwise check for incompleted type
3484 if Is_Incomplete_Or_Private_Type
(T
)
3485 and then No
(Underlying_Type
(T
))
3488 ("representation item must be after full type declaration", N
);
3491 -- If the type has incompleted components, a representation clause is
3492 -- illegal but stream attributes and Convention pragmas are correct.
3494 elsif Has_Private_Component
(T
) then
3495 if Nkind
(N
) = N_Pragma
then
3499 ("representation item must appear after type is fully defined",
3506 end Rep_Item_Too_Early
;
3508 -----------------------
3509 -- Rep_Item_Too_Late --
3510 -----------------------
3512 function Rep_Item_Too_Late
3515 FOnly
: Boolean := False) return Boolean
3518 Parent_Type
: Entity_Id
;
3521 -- Output the too late message. Note that this is not considered a
3522 -- serious error, since the effect is simply that we ignore the
3523 -- representation clause in this case.
3529 procedure Too_Late
is
3531 Error_Msg_N
("|representation item appears too late!", N
);
3534 -- Start of processing for Rep_Item_Too_Late
3537 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3538 -- types, which may be frozen if they appear in a representation clause
3539 -- for a local type.
3542 and then not From_With_Type
(T
)
3545 S
:= First_Subtype
(T
);
3547 if Present
(Freeze_Node
(S
)) then
3549 ("?no more representation items for }!", Freeze_Node
(S
), S
);
3554 -- Check for case of non-tagged derived type whose parent either has
3555 -- primitive operations, or is a by reference type (RM 13.1(10)).
3559 and then Is_Derived_Type
(T
)
3560 and then not Is_Tagged_Type
(T
)
3562 Parent_Type
:= Etype
(Base_Type
(T
));
3564 if Has_Primitive_Operations
(Parent_Type
) then
3567 ("primitive operations already defined for&!", N
, Parent_Type
);
3570 elsif Is_By_Reference_Type
(Parent_Type
) then
3573 ("parent type & is a by reference type!", N
, Parent_Type
);
3578 -- No error, link item into head of chain of rep items for the entity
3580 Record_Rep_Item
(T
, N
);
3582 end Rep_Item_Too_Late
;
3584 -------------------------
3585 -- Same_Representation --
3586 -------------------------
3588 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
3589 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
3590 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
3593 -- A quick check, if base types are the same, then we definitely have
3594 -- the same representation, because the subtype specific representation
3595 -- attributes (Size and Alignment) do not affect representation from
3596 -- the point of view of this test.
3598 if Base_Type
(T1
) = Base_Type
(T2
) then
3601 elsif Is_Private_Type
(Base_Type
(T2
))
3602 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
3607 -- Tagged types never have differing representations
3609 if Is_Tagged_Type
(T1
) then
3613 -- Representations are definitely different if conventions differ
3615 if Convention
(T1
) /= Convention
(T2
) then
3619 -- Representations are different if component alignments differ
3621 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
3623 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
3624 and then Component_Alignment
(T1
) /= Component_Alignment
(T2
)
3629 -- For arrays, the only real issue is component size. If we know the
3630 -- component size for both arrays, and it is the same, then that's
3631 -- good enough to know we don't have a change of representation.
3633 if Is_Array_Type
(T1
) then
3634 if Known_Component_Size
(T1
)
3635 and then Known_Component_Size
(T2
)
3636 and then Component_Size
(T1
) = Component_Size
(T2
)
3642 -- Types definitely have same representation if neither has non-standard
3643 -- representation since default representations are always consistent.
3644 -- If only one has non-standard representation, and the other does not,
3645 -- then we consider that they do not have the same representation. They
3646 -- might, but there is no way of telling early enough.
3648 if Has_Non_Standard_Rep
(T1
) then
3649 if not Has_Non_Standard_Rep
(T2
) then
3653 return not Has_Non_Standard_Rep
(T2
);
3656 -- Here the two types both have non-standard representation, and we
3657 -- need to determine if they have the same non-standard representation
3659 -- For arrays, we simply need to test if the component sizes are the
3660 -- same. Pragma Pack is reflected in modified component sizes, so this
3661 -- check also deals with pragma Pack.
3663 if Is_Array_Type
(T1
) then
3664 return Component_Size
(T1
) = Component_Size
(T2
);
3666 -- Tagged types always have the same representation, because it is not
3667 -- possible to specify different representations for common fields.
3669 elsif Is_Tagged_Type
(T1
) then
3672 -- Case of record types
3674 elsif Is_Record_Type
(T1
) then
3676 -- Packed status must conform
3678 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
3681 -- Otherwise we must check components. Typ2 maybe a constrained
3682 -- subtype with fewer components, so we compare the components
3683 -- of the base types.
3686 Record_Case
: declare
3687 CD1
, CD2
: Entity_Id
;
3689 function Same_Rep
return Boolean;
3690 -- CD1 and CD2 are either components or discriminants. This
3691 -- function tests whether the two have the same representation
3697 function Same_Rep
return Boolean is
3699 if No
(Component_Clause
(CD1
)) then
3700 return No
(Component_Clause
(CD2
));
3704 Present
(Component_Clause
(CD2
))
3706 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
3708 Esize
(CD1
) = Esize
(CD2
);
3712 -- Start processing for Record_Case
3715 if Has_Discriminants
(T1
) then
3716 CD1
:= First_Discriminant
(T1
);
3717 CD2
:= First_Discriminant
(T2
);
3719 -- The number of discriminants may be different if the
3720 -- derived type has fewer (constrained by values). The
3721 -- invisible discriminants retain the representation of
3722 -- the original, so the discrepancy does not per se
3723 -- indicate a different representation.
3726 and then Present
(CD2
)
3728 if not Same_Rep
then
3731 Next_Discriminant
(CD1
);
3732 Next_Discriminant
(CD2
);
3737 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
3738 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
3740 while Present
(CD1
) loop
3741 if not Same_Rep
then
3744 Next_Component
(CD1
);
3745 Next_Component
(CD2
);
3753 -- For enumeration types, we must check each literal to see if the
3754 -- representation is the same. Note that we do not permit enumeration
3755 -- reprsentation clauses for Character and Wide_Character, so these
3756 -- cases were already dealt with.
3758 elsif Is_Enumeration_Type
(T1
) then
3760 Enumeration_Case
: declare
3764 L1
:= First_Literal
(T1
);
3765 L2
:= First_Literal
(T2
);
3767 while Present
(L1
) loop
3768 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
3778 end Enumeration_Case
;
3780 -- Any other types have the same representation for these purposes
3785 end Same_Representation
;
3787 --------------------
3788 -- Set_Enum_Esize --
3789 --------------------
3791 procedure Set_Enum_Esize
(T
: Entity_Id
) is
3799 -- Find the minimum standard size (8,16,32,64) that fits
3801 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
3802 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
3805 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
3806 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3808 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
3811 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
3814 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
3819 if Hi
< Uint_2
**08 then
3820 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3822 elsif Hi
< Uint_2
**16 then
3825 elsif Hi
< Uint_2
**32 then
3828 else pragma Assert
(Hi
< Uint_2
**63);
3833 -- That minimum is the proper size unless we have a foreign convention
3834 -- and the size required is 32 or less, in which case we bump the size
3835 -- up to 32. This is required for C and C++ and seems reasonable for
3836 -- all other foreign conventions.
3838 if Has_Foreign_Convention
(T
)
3839 and then Esize
(T
) < Standard_Integer_Size
3841 Init_Esize
(T
, Standard_Integer_Size
);
3848 -----------------------------------
3849 -- Validate_Unchecked_Conversion --
3850 -----------------------------------
3852 procedure Validate_Unchecked_Conversion
3854 Act_Unit
: Entity_Id
)
3861 -- Obtain source and target types. Note that we call Ancestor_Subtype
3862 -- here because the processing for generic instantiation always makes
3863 -- subtypes, and we want the original frozen actual types.
3865 -- If we are dealing with private types, then do the check on their
3866 -- fully declared counterparts if the full declarations have been
3867 -- encountered (they don't have to be visible, but they must exist!)
3869 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
3871 if Is_Private_Type
(Source
)
3872 and then Present
(Underlying_Type
(Source
))
3874 Source
:= Underlying_Type
(Source
);
3877 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
3879 -- If either type is generic, the instantiation happens within a
3880 -- generic unit, and there is nothing to check. The proper check
3881 -- will happen when the enclosing generic is instantiated.
3883 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
3887 if Is_Private_Type
(Target
)
3888 and then Present
(Underlying_Type
(Target
))
3890 Target
:= Underlying_Type
(Target
);
3893 -- Source may be unconstrained array, but not target
3895 if Is_Array_Type
(Target
)
3896 and then not Is_Constrained
(Target
)
3899 ("unchecked conversion to unconstrained array not allowed", N
);
3903 -- Make entry in unchecked conversion table for later processing
3904 -- by Validate_Unchecked_Conversions, which will check sizes and
3905 -- alignments (using values set by the back-end where possible).
3906 -- This is only done if the appropriate warning is active
3908 if Warn_On_Unchecked_Conversion
then
3909 Unchecked_Conversions
.Append
3910 (New_Val
=> UC_Entry
'
3915 -- If both sizes are known statically now, then back end annotation
3916 -- is not required to do a proper check but if either size is not
3917 -- known statically, then we need the annotation.
3919 if Known_Static_RM_Size (Source)
3920 and then Known_Static_RM_Size (Target)
3924 Back_Annotate_Rep_Info := True;
3928 -- If unchecked conversion to access type, and access type is
3929 -- declared in the same unit as the unchecked conversion, then
3930 -- set the No_Strict_Aliasing flag (no strict aliasing is
3931 -- implicit in this situation).
3933 if Is_Access_Type (Target) and then
3934 In_Same_Source_Unit (Target, N)
3936 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
3939 -- Generate N_Validate_Unchecked_Conversion node for back end in
3940 -- case the back end needs to perform special validation checks.
3942 -- Shouldn't this be in exp_ch13, since the check only gets done
3943 -- if we have full expansion and the back end is called ???
3946 Make_Validate_Unchecked_Conversion (Sloc (N));
3947 Set_Source_Type (Vnode, Source);
3948 Set_Target_Type (Vnode, Target);
3950 -- If the unchecked conversion node is in a list, just insert before
3951 -- it. If not we have some strange case, not worth bothering about.
3953 if Is_List_Member (N) then
3954 Insert_After (N, Vnode);
3956 end Validate_Unchecked_Conversion;
3958 ------------------------------------
3959 -- Validate_Unchecked_Conversions --
3960 ------------------------------------
3962 procedure Validate_Unchecked_Conversions is
3964 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
3966 T : UC_Entry renames Unchecked_Conversions.Table (N);
3968 Enode : constant Node_Id := T.Enode;
3969 Source : constant Entity_Id := T.Source;
3970 Target : constant Entity_Id := T.Target;
3976 -- This validation check, which warns if we have unequal sizes
3977 -- for unchecked conversion, and thus potentially implementation
3978 -- dependent semantics, is one of the few occasions on which we
3979 -- use the official RM size instead of Esize. See description
3980 -- in Einfo "Handling of Type'Size Values" for details.
3982 if Serious_Errors_Detected = 0
3983 and then Known_Static_RM_Size (Source)
3984 and then Known_Static_RM_Size (Target)
3986 Source_Siz := RM_Size (Source);
3987 Target_Siz := RM_Size (Target);
3989 if Source_Siz /= Target_Siz then
3991 ("types for unchecked conversion have different sizes?",
3994 if All_Errors_Mode then
3995 Error_Msg_Name_1 := Chars (Source);
3996 Error_Msg_Uint_1 := Source_Siz;
3997 Error_Msg_Name_2 := Chars (Target);
3998 Error_Msg_Uint_2 := Target_Siz;
4000 ("\size of % is ^, size of % is ^?", Enode);
4002 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
4004 if Is_Discrete_Type (Source)
4005 and then Is_Discrete_Type (Target)
4007 if Source_Siz > Target_Siz then
4009 ("\^ high order bits of source will be ignored?",
4012 elsif Is_Unsigned_Type (Source) then
4014 ("\source will be extended with ^ high order " &
4015 "zero bits?", Enode);
4019 ("\source will be extended with ^ high order " &
4024 elsif Source_Siz < Target_Siz then
4025 if Is_Discrete_Type (Target) then
4026 if Bytes_Big_Endian then
4028 ("\target value will include ^ undefined " &
4033 ("\target value will include ^ undefined " &
4040 ("\^ trailing bits of target value will be " &
4041 "undefined?", Enode);
4044 else pragma Assert (Source_Siz > Target_Siz);
4046 ("\^ trailing bits of source will be ignored?",
4053 -- If both types are access types, we need to check the alignment.
4054 -- If the alignment of both is specified, we can do it here.
4056 if Serious_Errors_Detected = 0
4057 and then Ekind (Source) in Access_Kind
4058 and then Ekind (Target) in Access_Kind
4059 and then Target_Strict_Alignment
4060 and then Present (Designated_Type (Source))
4061 and then Present (Designated_Type (Target))
4064 D_Source : constant Entity_Id := Designated_Type (Source);
4065 D_Target : constant Entity_Id := Designated_Type (Target);
4068 if Known_Alignment (D_Source)
4069 and then Known_Alignment (D_Target)
4072 Source_Align : constant Uint := Alignment (D_Source);
4073 Target_Align : constant Uint := Alignment (D_Target);
4076 if Source_Align < Target_Align
4077 and then not Is_Tagged_Type (D_Source)
4079 Error_Msg_Uint_1 := Target_Align;
4080 Error_Msg_Uint_2 := Source_Align;
4081 Error_Msg_Node_2 := D_Source;
4083 ("alignment of & (^) is stricter than " &
4084 "alignment of & (^)?", Enode, D_Target);
4086 if All_Errors_Mode then
4088 ("\resulting access value may have invalid " &
4089 "alignment?", Enode);
4098 end Validate_Unchecked_Conversions;