1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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
);
307 -- Switch on particular attribute
315 -- Address attribute definition clause
317 when Attribute_Address
=> Address
: begin
318 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
320 if Present
(Address_Clause
(U_Ent
)) then
321 Error_Msg_N
("address already given for &", Nam
);
323 -- Case of address clause for subprogram
325 elsif Is_Subprogram
(U_Ent
) then
326 if Has_Homonym
(U_Ent
) then
328 ("address clause cannot be given " &
329 "for overloaded subprogram",
333 -- For subprograms, all address clauses are permitted,
334 -- and we mark the subprogram as having a deferred freeze
335 -- so that Gigi will not elaborate it too soon.
337 -- Above needs more comments, what is too soon about???
339 Set_Has_Delayed_Freeze
(U_Ent
);
341 -- Case of address clause for entry
343 elsif Ekind
(U_Ent
) = E_Entry
then
344 if Nkind
(Parent
(N
)) = N_Task_Body
then
346 ("entry address must be specified in task spec", Nam
);
349 -- For entries, we require a constant address
351 Check_Constant_Address_Clause
(Expr
, U_Ent
);
353 if Is_Task_Type
(Scope
(U_Ent
))
354 and then Comes_From_Source
(Scope
(U_Ent
))
357 ("?entry address declared for entry in task type", N
);
359 ("\?only one task can be declared of this type", N
);
362 Check_Restriction
(No_Obsolescent_Features
, N
);
364 if Warn_On_Obsolescent_Feature
then
366 ("attaching interrupt to task entry is an " &
367 "obsolescent feature ('R'M 'J.7.1)?", N
);
369 ("\use interrupt procedure instead?", N
);
372 -- Case of an address clause for a controlled object:
373 -- erroneous execution.
375 elsif Is_Controlled
(Etype
(U_Ent
)) then
377 ("?controlled object& must not be overlaid", Nam
, U_Ent
);
379 ("\?Program_Error will be raised at run time", Nam
);
380 Insert_Action
(Declaration_Node
(U_Ent
),
381 Make_Raise_Program_Error
(Loc
,
382 Reason
=> PE_Overlaid_Controlled_Object
));
384 -- Case of address clause for a (non-controlled) object
387 Ekind
(U_Ent
) = E_Variable
389 Ekind
(U_Ent
) = E_Constant
392 Expr
: constant Node_Id
:= Expression
(N
);
393 Aent
: constant Entity_Id
:= Address_Aliased_Entity
(Expr
);
396 -- Exported variables cannot have an address clause,
397 -- because this cancels the effect of the pragma Export
399 if Is_Exported
(U_Ent
) then
401 ("cannot export object with address clause", Nam
);
403 -- Overlaying controlled objects is erroneous
406 and then Is_Controlled
(Etype
(Aent
))
409 ("?controlled object must not be overlaid", Expr
);
411 ("\?Program_Error will be raised at run time", Expr
);
412 Insert_Action
(Declaration_Node
(U_Ent
),
413 Make_Raise_Program_Error
(Loc
,
414 Reason
=> PE_Overlaid_Controlled_Object
));
417 and then Ekind
(U_Ent
) = E_Constant
418 and then Ekind
(Aent
) /= E_Constant
420 Error_Msg_N
("constant overlays a variable?", Expr
);
422 elsif Present
(Renamed_Object
(U_Ent
)) then
424 ("address clause not allowed"
425 & " for a renaming declaration ('R'M 13.1(6))", Nam
);
427 -- Imported variables can have an address clause, but then
428 -- the import is pretty meaningless except to suppress
429 -- initializations, so we do not need such variables to
430 -- be statically allocated (and in fact it causes trouble
431 -- if the address clause is a local value).
433 elsif Is_Imported
(U_Ent
) then
434 Set_Is_Statically_Allocated
(U_Ent
, False);
437 -- We mark a possible modification of a variable with an
438 -- address clause, since it is likely aliasing is occurring.
440 Note_Possible_Modification
(Nam
);
442 -- Here we are checking for explicit overlap of one
443 -- variable by another, and if we find this, then we
444 -- mark the overlapped variable as also being aliased.
446 -- First case is where we have an explicit
448 -- for J'Address use K'Address;
450 -- In this case, we mark K as volatile
452 Mark_Aliased_Address_As_Volatile
(Expr
);
454 -- Second case is where we have a constant whose
455 -- definition is of the form of an adress as in:
457 -- A : constant Address := K'Address;
459 -- for B'Address use A;
461 -- In this case we also mark K as volatile
463 if Is_Entity_Name
(Expr
) then
465 Ent
: constant Entity_Id
:= Entity
(Expr
);
466 Decl
: constant Node_Id
:= Declaration_Node
(Ent
);
469 if Ekind
(Ent
) = E_Constant
470 and then Nkind
(Decl
) = N_Object_Declaration
471 and then Present
(Expression
(Decl
))
473 Mark_Aliased_Address_As_Volatile
479 -- Legality checks on the address clause for initialized
480 -- objects is deferred until the freeze point, because
481 -- a subsequent pragma might indicate that the object is
482 -- imported and thus not initialized.
484 Set_Has_Delayed_Freeze
(U_Ent
);
486 if Is_Exported
(U_Ent
) then
488 ("& cannot be exported if an address clause is given",
491 ("\define and export a variable " &
492 "that holds its address instead",
496 -- Entity has delayed freeze, so we will generate
497 -- an alignment check at the freeze point.
499 Set_Check_Address_Alignment
500 (N
, not Range_Checks_Suppressed
(U_Ent
));
502 -- Kill the size check code, since we are not allocating
503 -- the variable, it is somewhere else.
505 Kill_Size_Check_Code
(U_Ent
);
508 -- Not a valid entity for an address clause
511 Error_Msg_N
("address cannot be given for &", Nam
);
519 -- Alignment attribute definition clause
521 when Attribute_Alignment
=> Alignment_Block
: declare
522 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
527 if not Is_Type
(U_Ent
)
528 and then Ekind
(U_Ent
) /= E_Variable
529 and then Ekind
(U_Ent
) /= E_Constant
531 Error_Msg_N
("alignment cannot be given for &", Nam
);
533 elsif Has_Alignment_Clause
(U_Ent
) then
534 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
535 Error_Msg_N
("alignment clause previously given#", N
);
537 elsif Align
/= No_Uint
then
538 Set_Has_Alignment_Clause
(U_Ent
);
539 Set_Alignment
(U_Ent
, Align
);
547 -- Bit_Order attribute definition clause
549 when Attribute_Bit_Order
=> Bit_Order
: declare
551 if not Is_Record_Type
(U_Ent
) then
553 ("Bit_Order can only be defined for record type", Nam
);
556 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
558 if Etype
(Expr
) = Any_Type
then
561 elsif not Is_Static_Expression
(Expr
) then
563 ("Bit_Order requires static expression!", Expr
);
566 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
567 Set_Reverse_Bit_Order
(U_Ent
, True);
577 -- Component_Size attribute definition clause
579 when Attribute_Component_Size
=> Component_Size_Case
: declare
580 Csize
: constant Uint
:= Static_Integer
(Expr
);
583 New_Ctyp
: Entity_Id
;
587 if not Is_Array_Type
(U_Ent
) then
588 Error_Msg_N
("component size requires array type", Nam
);
592 Btype
:= Base_Type
(U_Ent
);
594 if Has_Component_Size_Clause
(Btype
) then
596 ("component size clase for& previously given", Nam
);
598 elsif Csize
/= No_Uint
then
599 Check_Size
(Expr
, Component_Type
(Btype
), Csize
, Biased
);
601 if Has_Aliased_Components
(Btype
)
607 ("component size incorrect for aliased components", N
);
611 -- For the biased case, build a declaration for a subtype
612 -- that will be used to represent the biased subtype that
613 -- reflects the biased representation of components. We need
614 -- this subtype to get proper conversions on referencing
615 -- elements of the array.
619 Make_Defining_Identifier
(Loc
,
620 Chars
=> New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
623 Make_Subtype_Declaration
(Loc
,
624 Defining_Identifier
=> New_Ctyp
,
625 Subtype_Indication
=>
626 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
628 Set_Parent
(Decl
, N
);
629 Analyze
(Decl
, Suppress
=> All_Checks
);
631 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
632 Set_Esize
(New_Ctyp
, Csize
);
633 Set_RM_Size
(New_Ctyp
, Csize
);
634 Init_Alignment
(New_Ctyp
);
635 Set_Has_Biased_Representation
(New_Ctyp
, True);
636 Set_Is_Itype
(New_Ctyp
, True);
637 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
639 Set_Component_Type
(Btype
, New_Ctyp
);
642 Set_Component_Size
(Btype
, Csize
);
643 Set_Has_Component_Size_Clause
(Btype
, True);
644 Set_Has_Non_Standard_Rep
(Btype
, True);
646 end Component_Size_Case
;
652 when Attribute_External_Tag
=> External_Tag
:
654 if not Is_Tagged_Type
(U_Ent
) then
655 Error_Msg_N
("should be a tagged type", Nam
);
658 Analyze_And_Resolve
(Expr
, Standard_String
);
660 if not Is_Static_Expression
(Expr
) then
662 ("static string required for tag name!", Nam
);
665 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
672 when Attribute_Input
=> Input
: declare
673 Subp
: Entity_Id
:= Empty
;
678 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
679 -- Return true if the entity is a function with an appropriate
680 -- profile for the Input attribute.
682 ----------------------
683 -- Has_Good_Profile --
684 ----------------------
686 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
688 Ok
: Boolean := False;
691 if Ekind
(Subp
) = E_Function
then
692 F
:= First_Formal
(Subp
);
694 if Present
(F
) and then No
(Next_Formal
(F
)) then
695 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
697 Designated_Type
(Etype
(F
)) =
698 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
700 Ok
:= Base_Type
(Etype
(Subp
)) = Base_Type
(Ent
);
706 end Has_Good_Profile
;
708 -- Start of processing for Input attribute definition
713 if not Is_Type
(U_Ent
) then
714 Error_Msg_N
("local name must be a subtype", Nam
);
718 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Input
);
721 and then Base_Type
(Etype
(Pnam
)) = Base_Type
(U_Ent
)
723 Error_Msg_Sloc
:= Sloc
(Pnam
);
724 Error_Msg_N
("input attribute already defined #", Nam
);
731 if Is_Entity_Name
(Expr
) then
732 if not Is_Overloaded
(Expr
) then
733 if Has_Good_Profile
(Entity
(Expr
)) then
734 Subp
:= Entity
(Expr
);
738 Get_First_Interp
(Expr
, I
, It
);
740 while Present
(It
.Nam
) loop
741 if Has_Good_Profile
(It
.Nam
) then
746 Get_Next_Interp
(I
, It
);
751 if Present
(Subp
) then
752 Set_Entity
(Expr
, Subp
);
753 Set_Etype
(Expr
, Etype
(Subp
));
754 New_Stream_Function
(N
, U_Ent
, Subp
, TSS_Stream_Input
);
756 Error_Msg_N
("incorrect expression for input attribute", Expr
);
765 -- Machine radix attribute definition clause
767 when Attribute_Machine_Radix
=> Machine_Radix
: declare
768 Radix
: constant Uint
:= Static_Integer
(Expr
);
771 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
772 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
774 elsif Has_Machine_Radix_Clause
(U_Ent
) then
775 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
776 Error_Msg_N
("machine radix clause previously given#", N
);
778 elsif Radix
/= No_Uint
then
779 Set_Has_Machine_Radix_Clause
(U_Ent
);
780 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
784 elsif Radix
= 10 then
785 Set_Machine_Radix_10
(U_Ent
);
787 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
796 -- Object_Size attribute definition clause
798 when Attribute_Object_Size
=> Object_Size
: declare
799 Size
: constant Uint
:= Static_Integer
(Expr
);
803 if not Is_Type
(U_Ent
) then
804 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
806 elsif Has_Object_Size_Clause
(U_Ent
) then
807 Error_Msg_N
("Object_Size already given for &", Nam
);
810 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
818 UI_Mod
(Size
, 64) /= 0
821 ("Object_Size must be 8, 16, 32, or multiple of 64",
825 Set_Esize
(U_Ent
, Size
);
826 Set_Has_Object_Size_Clause
(U_Ent
);
827 Alignment_Check_For_Esize_Change
(U_Ent
);
835 when Attribute_Output
=> Output
: declare
836 Subp
: Entity_Id
:= Empty
;
841 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
842 -- Return true if the entity is a procedure with an
843 -- appropriate profile for the output attribute.
845 ----------------------
846 -- Has_Good_Profile --
847 ----------------------
849 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
851 Ok
: Boolean := False;
854 if Ekind
(Subp
) = E_Procedure
then
855 F
:= First_Formal
(Subp
);
858 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
860 Designated_Type
(Etype
(F
)) =
861 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
865 and then Parameter_Mode
(F
) = E_In_Parameter
866 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
867 and then No
(Next_Formal
(F
));
873 end Has_Good_Profile
;
875 -- Start of processing for Output attribute definition
880 if not Is_Type
(U_Ent
) then
881 Error_Msg_N
("local name must be a subtype", Nam
);
885 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Output
);
889 Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
892 Error_Msg_Sloc
:= Sloc
(Pnam
);
893 Error_Msg_N
("output attribute already defined #", Nam
);
900 if Is_Entity_Name
(Expr
) then
901 if not Is_Overloaded
(Expr
) then
902 if Has_Good_Profile
(Entity
(Expr
)) then
903 Subp
:= Entity
(Expr
);
907 Get_First_Interp
(Expr
, I
, It
);
909 while Present
(It
.Nam
) loop
910 if Has_Good_Profile
(It
.Nam
) then
915 Get_Next_Interp
(I
, It
);
920 if Present
(Subp
) then
921 Set_Entity
(Expr
, Subp
);
922 Set_Etype
(Expr
, Etype
(Subp
));
923 New_Stream_Procedure
(N
, U_Ent
, Subp
, TSS_Stream_Output
);
925 Error_Msg_N
("incorrect expression for output attribute", Expr
);
934 when Attribute_Read
=> Read
: declare
935 Subp
: Entity_Id
:= Empty
;
940 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
941 -- Return true if the entity is a procedure with an appropriate
942 -- profile for the Read attribute.
944 ----------------------
945 -- Has_Good_Profile --
946 ----------------------
948 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
950 Ok
: Boolean := False;
953 if Ekind
(Subp
) = E_Procedure
then
954 F
:= First_Formal
(Subp
);
957 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
959 Designated_Type
(Etype
(F
)) =
960 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
964 and then Parameter_Mode
(F
) = E_Out_Parameter
965 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
966 and then No
(Next_Formal
(F
));
972 end Has_Good_Profile
;
974 -- Start of processing for Read attribute definition
979 if not Is_Type
(U_Ent
) then
980 Error_Msg_N
("local name must be a subtype", Nam
);
984 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Read
);
987 and then Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
990 Error_Msg_Sloc
:= Sloc
(Pnam
);
991 Error_Msg_N
("read attribute already defined #", Nam
);
998 if Is_Entity_Name
(Expr
) then
999 if not Is_Overloaded
(Expr
) then
1000 if Has_Good_Profile
(Entity
(Expr
)) then
1001 Subp
:= Entity
(Expr
);
1005 Get_First_Interp
(Expr
, I
, It
);
1007 while Present
(It
.Nam
) loop
1008 if Has_Good_Profile
(It
.Nam
) then
1013 Get_Next_Interp
(I
, It
);
1018 if Present
(Subp
) then
1019 Set_Entity
(Expr
, Subp
);
1020 Set_Etype
(Expr
, Etype
(Subp
));
1021 New_Stream_Procedure
(N
, U_Ent
, Subp
, TSS_Stream_Read
, True);
1023 Error_Msg_N
("incorrect expression for read attribute", Expr
);
1032 -- Size attribute definition clause
1034 when Attribute_Size
=> Size
: declare
1035 Size
: constant Uint
:= Static_Integer
(Expr
);
1042 if Has_Size_Clause
(U_Ent
) then
1043 Error_Msg_N
("size already given for &", Nam
);
1045 elsif not Is_Type
(U_Ent
)
1046 and then Ekind
(U_Ent
) /= E_Variable
1047 and then Ekind
(U_Ent
) /= E_Constant
1049 Error_Msg_N
("size cannot be given for &", Nam
);
1051 elsif Is_Array_Type
(U_Ent
)
1052 and then not Is_Constrained
(U_Ent
)
1055 ("size cannot be given for unconstrained array", Nam
);
1057 elsif Size
/= No_Uint
then
1058 if Is_Type
(U_Ent
) then
1061 Etyp
:= Etype
(U_Ent
);
1064 -- Check size, note that Gigi is in charge of checking
1065 -- that the size of an array or record type is OK. Also
1066 -- we do not check the size in the ordinary fixed-point
1067 -- case, since it is too early to do so (there may be a
1068 -- subsequent small clause that affects the size). We can
1069 -- check the size if a small clause has already been given.
1071 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
1072 or else Has_Small_Clause
(U_Ent
)
1074 Check_Size
(Expr
, Etyp
, Size
, Biased
);
1075 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1078 -- For types set RM_Size and Esize if possible
1080 if Is_Type
(U_Ent
) then
1081 Set_RM_Size
(U_Ent
, Size
);
1083 -- For scalar types, increase Object_Size to power of 2,
1084 -- but not less than a storage unit in any case (i.e.,
1085 -- normally this means it will be byte addressable).
1087 if Is_Scalar_Type
(U_Ent
) then
1088 if Size
<= System_Storage_Unit
then
1089 Init_Esize
(U_Ent
, System_Storage_Unit
);
1090 elsif Size
<= 16 then
1091 Init_Esize
(U_Ent
, 16);
1092 elsif Size
<= 32 then
1093 Init_Esize
(U_Ent
, 32);
1095 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
1098 -- For all other types, object size = value size. The
1099 -- backend will adjust as needed.
1102 Set_Esize
(U_Ent
, Size
);
1105 Alignment_Check_For_Esize_Change
(U_Ent
);
1107 -- For objects, set Esize only
1110 if Is_Elementary_Type
(Etyp
) then
1111 if Size
/= System_Storage_Unit
1113 Size
/= System_Storage_Unit
* 2
1115 Size
/= System_Storage_Unit
* 4
1117 Size
/= System_Storage_Unit
* 8
1119 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
1121 ("size for primitive object must be a power of 2"
1122 & " and at least ^", N
);
1126 Set_Esize
(U_Ent
, Size
);
1129 Set_Has_Size_Clause
(U_Ent
);
1137 -- Small attribute definition clause
1139 when Attribute_Small
=> Small
: declare
1140 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
1144 Analyze_And_Resolve
(Expr
, Any_Real
);
1146 if Etype
(Expr
) = Any_Type
then
1149 elsif not Is_Static_Expression
(Expr
) then
1150 Flag_Non_Static_Expr
1151 ("small requires static expression!", Expr
);
1155 Small
:= Expr_Value_R
(Expr
);
1157 if Small
<= Ureal_0
then
1158 Error_Msg_N
("small value must be greater than zero", Expr
);
1164 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
1166 ("small requires an ordinary fixed point type", Nam
);
1168 elsif Has_Small_Clause
(U_Ent
) then
1169 Error_Msg_N
("small already given for &", Nam
);
1171 elsif Small
> Delta_Value
(U_Ent
) then
1173 ("small value must not be greater then delta value", Nam
);
1176 Set_Small_Value
(U_Ent
, Small
);
1177 Set_Small_Value
(Implicit_Base
, Small
);
1178 Set_Has_Small_Clause
(U_Ent
);
1179 Set_Has_Small_Clause
(Implicit_Base
);
1180 Set_Has_Non_Standard_Rep
(Implicit_Base
);
1188 -- Storage_Size attribute definition clause
1190 when Attribute_Storage_Size
=> Storage_Size
: declare
1191 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
1195 if Is_Task_Type
(U_Ent
) then
1196 Check_Restriction
(No_Obsolescent_Features
, N
);
1198 if Warn_On_Obsolescent_Feature
then
1200 ("storage size clause for task is an " &
1201 "obsolescent feature ('R'M 'J.9)?", N
);
1203 ("\use Storage_Size pragma instead?", N
);
1209 if not Is_Access_Type
(U_Ent
)
1210 and then Ekind
(U_Ent
) /= E_Task_Type
1212 Error_Msg_N
("storage size cannot be given for &", Nam
);
1214 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
1216 ("storage size cannot be given for a derived access type",
1219 elsif Has_Storage_Size_Clause
(Btype
) then
1220 Error_Msg_N
("storage size already given for &", Nam
);
1223 Analyze_And_Resolve
(Expr
, Any_Integer
);
1225 if Is_Access_Type
(U_Ent
) then
1227 if Present
(Associated_Storage_Pool
(U_Ent
)) then
1228 Error_Msg_N
("storage pool already given for &", Nam
);
1232 if Compile_Time_Known_Value
(Expr
)
1233 and then Expr_Value
(Expr
) = 0
1235 Set_No_Pool_Assigned
(Btype
);
1238 else -- Is_Task_Type (U_Ent)
1239 Sprag
:= Get_Rep_Pragma
(Btype
, Name_Storage_Size
);
1241 if Present
(Sprag
) then
1242 Error_Msg_Sloc
:= Sloc
(Sprag
);
1244 ("Storage_Size already specified#", Nam
);
1249 Set_Has_Storage_Size_Clause
(Btype
);
1257 -- Storage_Pool attribute definition clause
1259 when Attribute_Storage_Pool
=> Storage_Pool
: declare
1264 if Ekind
(U_Ent
) /= E_Access_Type
1265 and then Ekind
(U_Ent
) /= E_General_Access_Type
1268 "storage pool can only be given for access types", Nam
);
1271 elsif Is_Derived_Type
(U_Ent
) then
1273 ("storage pool cannot be given for a derived access type",
1276 elsif Has_Storage_Size_Clause
(U_Ent
) then
1277 Error_Msg_N
("storage size already given for &", Nam
);
1280 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
1281 Error_Msg_N
("storage pool already given for &", Nam
);
1286 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
1288 if Nkind
(Expr
) = N_Type_Conversion
then
1289 T
:= Etype
(Expression
(Expr
));
1294 -- The Stack_Bounded_Pool is used internally for implementing
1295 -- access types with a Storage_Size. Since it only work
1296 -- properly when used on one specific type, we need to check
1297 -- that it is not highjacked improperly:
1298 -- type T is access Integer;
1299 -- for T'Storage_Size use n;
1300 -- type Q is access Float;
1301 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
1303 if Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
) then
1304 Error_Msg_N
("non-sharable internal Pool", Expr
);
1308 -- If the argument is a name that is not an entity name, then
1309 -- we construct a renaming operation to define an entity of
1310 -- type storage pool.
1312 if not Is_Entity_Name
(Expr
)
1313 and then Is_Object_Reference
(Expr
)
1316 Make_Defining_Identifier
(Loc
,
1317 Chars
=> New_Internal_Name
('P'));
1320 Rnode
: constant Node_Id
:=
1321 Make_Object_Renaming_Declaration
(Loc
,
1322 Defining_Identifier
=> Pool
,
1324 New_Occurrence_Of
(Etype
(Expr
), Loc
),
1328 Insert_Before
(N
, Rnode
);
1330 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1333 elsif Is_Entity_Name
(Expr
) then
1334 Pool
:= Entity
(Expr
);
1336 -- If pool is a renamed object, get original one. This can
1337 -- happen with an explicit renaming, and within instances.
1339 while Present
(Renamed_Object
(Pool
))
1340 and then Is_Entity_Name
(Renamed_Object
(Pool
))
1342 Pool
:= Entity
(Renamed_Object
(Pool
));
1345 if Present
(Renamed_Object
(Pool
))
1346 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
1347 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
1349 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
1352 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1354 elsif Nkind
(Expr
) = N_Type_Conversion
1355 and then Is_Entity_Name
(Expression
(Expr
))
1356 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
1358 Pool
:= Entity
(Expression
(Expr
));
1359 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1362 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
1371 -- Value_Size attribute definition clause
1373 when Attribute_Value_Size
=> Value_Size
: declare
1374 Size
: constant Uint
:= Static_Integer
(Expr
);
1378 if not Is_Type
(U_Ent
) then
1379 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
1382 (Get_Attribute_Definition_Clause
1383 (U_Ent
, Attribute_Value_Size
))
1385 Error_Msg_N
("Value_Size already given for &", Nam
);
1388 if Is_Elementary_Type
(U_Ent
) then
1389 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
1390 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1393 Set_RM_Size
(U_Ent
, Size
);
1401 -- Write attribute definition clause
1402 -- check for class-wide case will be performed later
1404 when Attribute_Write
=> Write
: declare
1405 Subp
: Entity_Id
:= Empty
;
1410 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
1411 -- Return true if the entity is a procedure with an
1412 -- appropriate profile for the write attribute.
1414 ----------------------
1415 -- Has_Good_Profile --
1416 ----------------------
1418 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
1420 Ok
: Boolean := False;
1423 if Ekind
(Subp
) = E_Procedure
then
1424 F
:= First_Formal
(Subp
);
1427 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
1429 Designated_Type
(Etype
(F
)) =
1430 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
1434 and then Parameter_Mode
(F
) = E_In_Parameter
1435 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
1436 and then No
(Next_Formal
(F
));
1442 end Has_Good_Profile
;
1444 -- Start of processing for Write attribute definition
1449 if not Is_Type
(U_Ent
) then
1450 Error_Msg_N
("local name must be a subtype", Nam
);
1454 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Stream_Write
);
1457 and then Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
1460 Error_Msg_Sloc
:= Sloc
(Pnam
);
1461 Error_Msg_N
("write attribute already defined #", Nam
);
1467 if Is_Entity_Name
(Expr
) then
1468 if not Is_Overloaded
(Expr
) then
1469 if Has_Good_Profile
(Entity
(Expr
)) then
1470 Subp
:= Entity
(Expr
);
1474 Get_First_Interp
(Expr
, I
, It
);
1476 while Present
(It
.Nam
) loop
1477 if Has_Good_Profile
(It
.Nam
) then
1482 Get_Next_Interp
(I
, It
);
1487 if Present
(Subp
) then
1488 Set_Entity
(Expr
, Subp
);
1489 Set_Etype
(Expr
, Etype
(Subp
));
1490 New_Stream_Procedure
(N
, U_Ent
, Subp
, TSS_Stream_Write
);
1492 Error_Msg_N
("incorrect expression for write attribute", Expr
);
1497 -- All other attributes cannot be set
1501 ("attribute& cannot be set with definition clause", N
);
1505 -- The test for the type being frozen must be performed after
1506 -- any expression the clause has been analyzed since the expression
1507 -- itself might cause freezing that makes the clause illegal.
1509 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
1512 end Analyze_Attribute_Definition_Clause
;
1514 ----------------------------
1515 -- Analyze_Code_Statement --
1516 ----------------------------
1518 procedure Analyze_Code_Statement
(N
: Node_Id
) is
1519 HSS
: constant Node_Id
:= Parent
(N
);
1520 SBody
: constant Node_Id
:= Parent
(HSS
);
1521 Subp
: constant Entity_Id
:= Current_Scope
;
1528 -- Analyze and check we get right type, note that this implements the
1529 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1530 -- is the only way that Asm_Insn could possibly be visible.
1532 Analyze_And_Resolve
(Expression
(N
));
1534 if Etype
(Expression
(N
)) = Any_Type
then
1536 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
1537 Error_Msg_N
("incorrect type for code statement", N
);
1541 -- Make sure we appear in the handled statement sequence of a
1542 -- subprogram (RM 13.8(3)).
1544 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
1545 or else Nkind
(SBody
) /= N_Subprogram_Body
1548 ("code statement can only appear in body of subprogram", N
);
1552 -- Do remaining checks (RM 13.8(3)) if not already done
1554 if not Is_Machine_Code_Subprogram
(Subp
) then
1555 Set_Is_Machine_Code_Subprogram
(Subp
);
1557 -- No exception handlers allowed
1559 if Present
(Exception_Handlers
(HSS
)) then
1561 ("exception handlers not permitted in machine code subprogram",
1562 First
(Exception_Handlers
(HSS
)));
1565 -- No declarations other than use clauses and pragmas (we allow
1566 -- certain internally generated declarations as well).
1568 Decl
:= First
(Declarations
(SBody
));
1569 while Present
(Decl
) loop
1570 DeclO
:= Original_Node
(Decl
);
1571 if Comes_From_Source
(DeclO
)
1572 and then Nkind
(DeclO
) /= N_Pragma
1573 and then Nkind
(DeclO
) /= N_Use_Package_Clause
1574 and then Nkind
(DeclO
) /= N_Use_Type_Clause
1575 and then Nkind
(DeclO
) /= N_Implicit_Label_Declaration
1578 ("this declaration not allowed in machine code subprogram",
1585 -- No statements other than code statements, pragmas, and labels.
1586 -- Again we allow certain internally generated statements.
1588 Stmt
:= First
(Statements
(HSS
));
1589 while Present
(Stmt
) loop
1590 StmtO
:= Original_Node
(Stmt
);
1591 if Comes_From_Source
(StmtO
)
1592 and then Nkind
(StmtO
) /= N_Pragma
1593 and then Nkind
(StmtO
) /= N_Label
1594 and then Nkind
(StmtO
) /= N_Code_Statement
1597 ("this statement is not allowed in machine code subprogram",
1604 end Analyze_Code_Statement
;
1606 -----------------------------------------------
1607 -- Analyze_Enumeration_Representation_Clause --
1608 -----------------------------------------------
1610 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
1611 Ident
: constant Node_Id
:= Identifier
(N
);
1612 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
1613 Enumtype
: Entity_Id
;
1619 Err
: Boolean := False;
1621 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
1622 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
1627 -- First some basic error checks
1630 Enumtype
:= Entity
(Ident
);
1632 if Enumtype
= Any_Type
1633 or else Rep_Item_Too_Early
(Enumtype
, N
)
1637 Enumtype
:= Underlying_Type
(Enumtype
);
1640 if not Is_Enumeration_Type
(Enumtype
) then
1642 ("enumeration type required, found}",
1643 Ident
, First_Subtype
(Enumtype
));
1647 -- Ignore rep clause on generic actual type. This will already have
1648 -- been flagged on the template as an error, and this is the safest
1649 -- way to ensure we don't get a junk cascaded message in the instance.
1651 if Is_Generic_Actual_Type
(Enumtype
) then
1654 -- Type must be in current scope
1656 elsif Scope
(Enumtype
) /= Current_Scope
then
1657 Error_Msg_N
("type must be declared in this scope", Ident
);
1660 -- Type must be a first subtype
1662 elsif not Is_First_Subtype
(Enumtype
) then
1663 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
1666 -- Ignore duplicate rep clause
1668 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
1669 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
1672 -- Don't allow rep clause if root type is standard [wide_]character
1674 elsif Root_Type
(Enumtype
) = Standard_Character
1675 or else Root_Type
(Enumtype
) = Standard_Wide_Character
1677 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
1680 -- All tests passed, so set rep clause in place
1683 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
1684 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
1687 -- Now we process the aggregate. Note that we don't use the normal
1688 -- aggregate code for this purpose, because we don't want any of the
1689 -- normal expansion activities, and a number of special semantic
1690 -- rules apply (including the component type being any integer type)
1692 -- Badent signals that we found some incorrect entries processing
1693 -- the list. The final checks for completeness and ordering are
1694 -- skipped in this case.
1696 Elit
:= First_Literal
(Enumtype
);
1698 -- First the positional entries if any
1700 if Present
(Expressions
(Aggr
)) then
1701 Expr
:= First
(Expressions
(Aggr
));
1702 while Present
(Expr
) loop
1704 Error_Msg_N
("too many entries in aggregate", Expr
);
1708 Val
:= Static_Integer
(Expr
);
1710 if Val
= No_Uint
then
1713 elsif Val
< Lo
or else Hi
< Val
then
1714 Error_Msg_N
("value outside permitted range", Expr
);
1718 Set_Enumeration_Rep
(Elit
, Val
);
1719 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
1725 -- Now process the named entries if present
1727 if Present
(Component_Associations
(Aggr
)) then
1728 Assoc
:= First
(Component_Associations
(Aggr
));
1729 while Present
(Assoc
) loop
1730 Choice
:= First
(Choices
(Assoc
));
1732 if Present
(Next
(Choice
)) then
1734 ("multiple choice not allowed here", Next
(Choice
));
1738 if Nkind
(Choice
) = N_Others_Choice
then
1739 Error_Msg_N
("others choice not allowed here", Choice
);
1742 elsif Nkind
(Choice
) = N_Range
then
1743 -- ??? should allow zero/one element range here
1744 Error_Msg_N
("range not allowed here", Choice
);
1748 Analyze_And_Resolve
(Choice
, Enumtype
);
1750 if Is_Entity_Name
(Choice
)
1751 and then Is_Type
(Entity
(Choice
))
1753 Error_Msg_N
("subtype name not allowed here", Choice
);
1755 -- ??? should allow static subtype with zero/one entry
1757 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
1758 if not Is_Static_Expression
(Choice
) then
1759 Flag_Non_Static_Expr
1760 ("non-static expression used for choice!", Choice
);
1764 Elit
:= Expr_Value_E
(Choice
);
1766 if Present
(Enumeration_Rep_Expr
(Elit
)) then
1767 Error_Msg_Sloc
:= Sloc
(Enumeration_Rep_Expr
(Elit
));
1769 ("representation for& previously given#",
1774 Set_Enumeration_Rep_Expr
(Elit
, Choice
);
1776 Expr
:= Expression
(Assoc
);
1777 Val
:= Static_Integer
(Expr
);
1779 if Val
= No_Uint
then
1782 elsif Val
< Lo
or else Hi
< Val
then
1783 Error_Msg_N
("value outside permitted range", Expr
);
1787 Set_Enumeration_Rep
(Elit
, Val
);
1796 -- Aggregate is fully processed. Now we check that a full set of
1797 -- representations was given, and that they are in range and in order.
1798 -- These checks are only done if no other errors occurred.
1804 Elit
:= First_Literal
(Enumtype
);
1805 while Present
(Elit
) loop
1806 if No
(Enumeration_Rep_Expr
(Elit
)) then
1807 Error_Msg_NE
("missing representation for&!", N
, Elit
);
1810 Val
:= Enumeration_Rep
(Elit
);
1812 if Min
= No_Uint
then
1816 if Val
/= No_Uint
then
1817 if Max
/= No_Uint
and then Val
<= Max
then
1819 ("enumeration value for& not ordered!",
1820 Enumeration_Rep_Expr
(Elit
), Elit
);
1826 -- If there is at least one literal whose representation
1827 -- is not equal to the Pos value, then note that this
1828 -- enumeration type has a non-standard representation.
1830 if Val
/= Enumeration_Pos
(Elit
) then
1831 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
1838 -- Now set proper size information
1841 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
1844 if Has_Size_Clause
(Enumtype
) then
1845 if Esize
(Enumtype
) >= Minsize
then
1850 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
1852 if Esize
(Enumtype
) < Minsize
then
1853 Error_Msg_N
("previously given size is too small", N
);
1856 Set_Has_Biased_Representation
(Enumtype
);
1861 Set_RM_Size
(Enumtype
, Minsize
);
1862 Set_Enum_Esize
(Enumtype
);
1865 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
1866 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
1867 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
1871 -- We repeat the too late test in case it froze itself!
1873 if Rep_Item_Too_Late
(Enumtype
, N
) then
1876 end Analyze_Enumeration_Representation_Clause
;
1878 ----------------------------
1879 -- Analyze_Free_Statement --
1880 ----------------------------
1882 procedure Analyze_Free_Statement
(N
: Node_Id
) is
1884 Analyze
(Expression
(N
));
1885 end Analyze_Free_Statement
;
1887 ------------------------------------------
1888 -- Analyze_Record_Representation_Clause --
1889 ------------------------------------------
1891 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
1892 Loc
: constant Source_Ptr
:= Sloc
(N
);
1893 Ident
: constant Node_Id
:= Identifier
(N
);
1894 Rectype
: Entity_Id
;
1900 Hbit
: Uint
:= Uint_0
;
1905 Max_Bit_So_Far
: Uint
;
1906 -- Records the maximum bit position so far. If all field positions
1907 -- are monotonically increasing, then we can skip the circuit for
1908 -- checking for overlap, since no overlap is possible.
1910 Overlap_Check_Required
: Boolean;
1911 -- Used to keep track of whether or not an overlap check is required
1913 Ccount
: Natural := 0;
1914 -- Number of component clauses in record rep clause
1918 Rectype
:= Entity
(Ident
);
1920 if Rectype
= Any_Type
1921 or else Rep_Item_Too_Early
(Rectype
, N
)
1925 Rectype
:= Underlying_Type
(Rectype
);
1928 -- First some basic error checks
1930 if not Is_Record_Type
(Rectype
) then
1932 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
1935 elsif Is_Unchecked_Union
(Rectype
) then
1937 ("record rep clause not allowed for Unchecked_Union", N
);
1939 elsif Scope
(Rectype
) /= Current_Scope
then
1940 Error_Msg_N
("type must be declared in this scope", N
);
1943 elsif not Is_First_Subtype
(Rectype
) then
1944 Error_Msg_N
("cannot give record rep clause for subtype", N
);
1947 elsif Has_Record_Rep_Clause
(Rectype
) then
1948 Error_Msg_N
("duplicate record rep clause ignored", N
);
1951 elsif Rep_Item_Too_Late
(Rectype
, N
) then
1955 if Present
(Mod_Clause
(N
)) then
1957 Loc
: constant Source_Ptr
:= Sloc
(N
);
1958 M
: constant Node_Id
:= Mod_Clause
(N
);
1959 P
: constant List_Id
:= Pragmas_Before
(M
);
1963 pragma Warnings
(Off
, Mod_Val
);
1966 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
1968 if Warn_On_Obsolescent_Feature
then
1970 ("mod clause is an obsolescent feature ('R'M 'J.8)?", N
);
1972 ("\use alignment attribute definition clause instead?", N
);
1979 -- In ASIS_Mode mode, expansion is disabled, but we must
1980 -- convert the Mod clause into an alignment clause anyway, so
1981 -- that the back-end can compute and back-annotate properly the
1982 -- size and alignment of types that may include this record.
1984 if Operating_Mode
= Check_Semantics
1988 Make_Attribute_Definition_Clause
(Loc
,
1989 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
1990 Chars
=> Name_Alignment
,
1991 Expression
=> Relocate_Node
(Expression
(M
)));
1993 Set_From_At_Mod
(AtM_Nod
);
1994 Insert_After
(N
, AtM_Nod
);
1995 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
1996 Set_Mod_Clause
(N
, Empty
);
1999 -- Get the alignment value to perform error checking
2001 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
2007 -- Clear any existing component clauses for the type (this happens
2008 -- with derived types, where we are now overriding the original)
2010 Fent
:= First_Entity
(Rectype
);
2013 while Present
(Comp
) loop
2014 if Ekind
(Comp
) = E_Component
2015 or else Ekind
(Comp
) = E_Discriminant
2017 Set_Component_Clause
(Comp
, Empty
);
2023 -- All done if no component clauses
2025 CC
:= First
(Component_Clauses
(N
));
2031 -- If a tag is present, then create a component clause that places
2032 -- it at the start of the record (otherwise gigi may place it after
2033 -- other fields that have rep clauses).
2035 if Nkind
(Fent
) = N_Defining_Identifier
2036 and then Chars
(Fent
) = Name_uTag
2038 Set_Component_Bit_Offset
(Fent
, Uint_0
);
2039 Set_Normalized_Position
(Fent
, Uint_0
);
2040 Set_Normalized_First_Bit
(Fent
, Uint_0
);
2041 Set_Normalized_Position_Max
(Fent
, Uint_0
);
2042 Init_Esize
(Fent
, System_Address_Size
);
2044 Set_Component_Clause
(Fent
,
2045 Make_Component_Clause
(Loc
,
2047 Make_Identifier
(Loc
,
2048 Chars
=> Name_uTag
),
2051 Make_Integer_Literal
(Loc
,
2055 Make_Integer_Literal
(Loc
,
2059 Make_Integer_Literal
(Loc
,
2060 UI_From_Int
(System_Address_Size
))));
2062 Ccount
:= Ccount
+ 1;
2065 -- A representation like this applies to the base type
2067 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
2068 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
2069 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
2071 Max_Bit_So_Far
:= Uint_Minus_1
;
2072 Overlap_Check_Required
:= False;
2074 -- Process the component clauses
2076 while Present
(CC
) loop
2078 -- If pragma, just analyze it
2080 if Nkind
(CC
) = N_Pragma
then
2083 -- Processing for real component clause
2086 Ccount
:= Ccount
+ 1;
2087 Posit
:= Static_Integer
(Position
(CC
));
2088 Fbit
:= Static_Integer
(First_Bit
(CC
));
2089 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2092 and then Fbit
/= No_Uint
2093 and then Lbit
/= No_Uint
2097 ("position cannot be negative", Position
(CC
));
2101 ("first bit cannot be negative", First_Bit
(CC
));
2103 -- Values look OK, so find the corresponding record component
2104 -- Even though the syntax allows an attribute reference for
2105 -- implementation-defined components, GNAT does not allow the
2106 -- tag to get an explicit position.
2108 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
2109 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
2110 Error_Msg_N
("position of tag cannot be specified", CC
);
2112 Error_Msg_N
("illegal component name", CC
);
2116 Comp
:= First_Entity
(Rectype
);
2117 while Present
(Comp
) loop
2118 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
2124 -- Maybe component of base type that is absent from
2125 -- statically constrained first subtype.
2127 Comp
:= First_Entity
(Base_Type
(Rectype
));
2128 while Present
(Comp
) loop
2129 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
2136 ("component clause is for non-existent field", CC
);
2138 elsif Present
(Component_Clause
(Comp
)) then
2139 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
2141 ("component clause previously given#", CC
);
2144 -- Update Fbit and Lbit to the actual bit number
2146 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
2147 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
2149 if Fbit
<= Max_Bit_So_Far
then
2150 Overlap_Check_Required
:= True;
2152 Max_Bit_So_Far
:= Lbit
;
2155 if Has_Size_Clause
(Rectype
)
2156 and then Esize
(Rectype
) <= Lbit
2159 ("bit number out of range of specified size",
2162 Set_Component_Clause
(Comp
, CC
);
2163 Set_Component_Bit_Offset
(Comp
, Fbit
);
2164 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
2165 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
2166 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
2168 Set_Normalized_Position_Max
2169 (Fent
, Normalized_Position
(Fent
));
2171 if Is_Tagged_Type
(Rectype
)
2172 and then Fbit
< System_Address_Size
2175 ("component overlaps tag field of&",
2179 -- This information is also set in the corresponding
2180 -- component of the base type, found by accessing the
2181 -- Original_Record_Component link if it is present.
2183 Ocomp
:= Original_Record_Component
(Comp
);
2190 (Component_Name
(CC
),
2195 Set_Has_Biased_Representation
(Comp
, Biased
);
2197 if Present
(Ocomp
) then
2198 Set_Component_Clause
(Ocomp
, CC
);
2199 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
2200 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
2201 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
2202 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
2204 Set_Normalized_Position_Max
2205 (Ocomp
, Normalized_Position
(Ocomp
));
2207 Set_Has_Biased_Representation
2208 (Ocomp
, Has_Biased_Representation
(Comp
));
2211 if Esize
(Comp
) < 0 then
2212 Error_Msg_N
("component size is negative", CC
);
2223 -- Now that we have processed all the component clauses, check for
2224 -- overlap. We have to leave this till last, since the components
2225 -- can appear in any arbitrary order in the representation clause.
2227 -- We do not need this check if all specified ranges were monotonic,
2228 -- as recorded by Overlap_Check_Required being False at this stage.
2230 -- This first section checks if there are any overlapping entries
2231 -- at all. It does this by sorting all entries and then seeing if
2232 -- there are any overlaps. If there are none, then that is decisive,
2233 -- but if there are overlaps, they may still be OK (they may result
2234 -- from fields in different variants).
2236 if Overlap_Check_Required
then
2237 Overlap_Check1
: declare
2239 OC_Fbit
: array (0 .. Ccount
) of Uint
;
2240 -- First-bit values for component clauses, the value is the
2241 -- offset of the first bit of the field from start of record.
2242 -- The zero entry is for use in sorting.
2244 OC_Lbit
: array (0 .. Ccount
) of Uint
;
2245 -- Last-bit values for component clauses, the value is the
2246 -- offset of the last bit of the field from start of record.
2247 -- The zero entry is for use in sorting.
2249 OC_Count
: Natural := 0;
2250 -- Count of entries in OC_Fbit and OC_Lbit
2252 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
2253 -- Compare routine for Sort (See GNAT.Heap_Sort_A)
2255 procedure OC_Move
(From
: Natural; To
: Natural);
2256 -- Move routine for Sort (see GNAT.Heap_Sort_A)
2258 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
2260 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
2263 procedure OC_Move
(From
: Natural; To
: Natural) is
2265 OC_Fbit
(To
) := OC_Fbit
(From
);
2266 OC_Lbit
(To
) := OC_Lbit
(From
);
2270 CC
:= First
(Component_Clauses
(N
));
2271 while Present
(CC
) loop
2272 if Nkind
(CC
) /= N_Pragma
then
2273 Posit
:= Static_Integer
(Position
(CC
));
2274 Fbit
:= Static_Integer
(First_Bit
(CC
));
2275 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2278 and then Fbit
/= No_Uint
2279 and then Lbit
/= No_Uint
2281 OC_Count
:= OC_Count
+ 1;
2282 Posit
:= Posit
* SSU
;
2283 OC_Fbit
(OC_Count
) := Fbit
+ Posit
;
2284 OC_Lbit
(OC_Count
) := Lbit
+ Posit
;
2293 OC_Move
'Unrestricted_Access,
2294 OC_Lt
'Unrestricted_Access);
2296 Overlap_Check_Required
:= False;
2297 for J
in 1 .. OC_Count
- 1 loop
2298 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
2299 Overlap_Check_Required
:= True;
2306 -- If Overlap_Check_Required is still True, then we have to do
2307 -- the full scale overlap check, since we have at least two fields
2308 -- that do overlap, and we need to know if that is OK since they
2309 -- are in the same variant, or whether we have a definite problem
2311 if Overlap_Check_Required
then
2312 Overlap_Check2
: declare
2313 C1_Ent
, C2_Ent
: Entity_Id
;
2314 -- Entities of components being checked for overlap
2317 -- Component_List node whose Component_Items are being checked
2320 -- Component declaration for component being checked
2323 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
2325 -- Loop through all components in record. For each component check
2326 -- for overlap with any of the preceding elements on the component
2327 -- list containing the component, and also, if the component is in
2328 -- a variant, check against components outside the case structure.
2329 -- This latter test is repeated recursively up the variant tree.
2331 Main_Component_Loop
: while Present
(C1_Ent
) loop
2332 if Ekind
(C1_Ent
) /= E_Component
2333 and then Ekind
(C1_Ent
) /= E_Discriminant
2335 goto Continue_Main_Component_Loop
;
2338 -- Skip overlap check if entity has no declaration node. This
2339 -- happens with discriminants in constrained derived types.
2340 -- Probably we are missing some checks as a result, but that
2341 -- does not seem terribly serious ???
2343 if No
(Declaration_Node
(C1_Ent
)) then
2344 goto Continue_Main_Component_Loop
;
2347 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
2349 -- Loop through component lists that need checking. Check the
2350 -- current component list and all lists in variants above us.
2352 Component_List_Loop
: loop
2354 -- If derived type definition, go to full declaration
2355 -- If at outer level, check discriminants if there are any
2357 if Nkind
(Clist
) = N_Derived_Type_Definition
then
2358 Clist
:= Parent
(Clist
);
2361 -- Outer level of record definition, check discriminants
2363 if Nkind
(Clist
) = N_Full_Type_Declaration
2364 or else Nkind
(Clist
) = N_Private_Type_Declaration
2366 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
2368 First_Discriminant
(Defining_Identifier
(Clist
));
2370 while Present
(C2_Ent
) loop
2371 exit when C1_Ent
= C2_Ent
;
2372 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2373 Next_Discriminant
(C2_Ent
);
2377 -- Record extension case
2379 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
2382 -- Otherwise check one component list
2385 Citem
:= First
(Component_Items
(Clist
));
2387 while Present
(Citem
) loop
2388 if Nkind
(Citem
) = N_Component_Declaration
then
2389 C2_Ent
:= Defining_Identifier
(Citem
);
2390 exit when C1_Ent
= C2_Ent
;
2391 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2398 -- Check for variants above us (the parent of the Clist can
2399 -- be a variant, in which case its parent is a variant part,
2400 -- and the parent of the variant part is a component list
2401 -- whose components must all be checked against the current
2402 -- component for overlap.
2404 if Nkind
(Parent
(Clist
)) = N_Variant
then
2405 Clist
:= Parent
(Parent
(Parent
(Clist
)));
2407 -- Check for possible discriminant part in record, this is
2408 -- treated essentially as another level in the recursion.
2409 -- For this case we have the parent of the component list
2410 -- is the record definition, and its parent is the full
2411 -- type declaration which contains the discriminant
2414 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
2415 Clist
:= Parent
(Parent
((Clist
)));
2417 -- If neither of these two cases, we are at the top of
2421 exit Component_List_Loop
;
2423 end loop Component_List_Loop
;
2425 <<Continue_Main_Component_Loop
>>
2426 Next_Entity
(C1_Ent
);
2428 end loop Main_Component_Loop
;
2432 -- For records that have component clauses for all components, and
2433 -- whose size is less than or equal to 32, we need to know the size
2434 -- in the front end to activate possible packed array processing
2435 -- where the component type is a record.
2437 -- At this stage Hbit + 1 represents the first unused bit from all
2438 -- the component clauses processed, so if the component clauses are
2439 -- complete, then this is the length of the record.
2441 -- For records longer than System.Storage_Unit, and for those where
2442 -- not all components have component clauses, the back end determines
2443 -- the length (it may for example be appopriate to round up the size
2444 -- to some convenient boundary, based on alignment considerations etc).
2446 if Unknown_RM_Size
(Rectype
)
2447 and then Hbit
+ 1 <= 32
2449 -- Nothing to do if at least one component with no component clause
2451 Comp
:= First_Entity
(Rectype
);
2452 while Present
(Comp
) loop
2453 if Ekind
(Comp
) = E_Component
2454 or else Ekind
(Comp
) = E_Discriminant
2456 if No
(Component_Clause
(Comp
)) then
2464 -- If we fall out of loop, all components have component clauses
2465 -- and so we can set the size to the maximum value.
2467 Set_RM_Size
(Rectype
, Hbit
+ 1);
2469 end Analyze_Record_Representation_Clause
;
2471 -----------------------------
2472 -- Check_Component_Overlap --
2473 -----------------------------
2475 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
2477 if Present
(Component_Clause
(C1_Ent
))
2478 and then Present
(Component_Clause
(C2_Ent
))
2480 -- Exclude odd case where we have two tag fields in the same
2481 -- record, both at location zero. This seems a bit strange,
2482 -- but it seems to happen in some circumstances ???
2484 if Chars
(C1_Ent
) = Name_uTag
2485 and then Chars
(C2_Ent
) = Name_uTag
2490 -- Here we check if the two fields overlap
2493 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
2494 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
2495 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
2496 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
2499 if E2
<= S1
or else E1
<= S2
then
2503 Component_Name
(Component_Clause
(C2_Ent
));
2504 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
2506 Component_Name
(Component_Clause
(C1_Ent
));
2508 ("component& overlaps & #",
2509 Component_Name
(Component_Clause
(C1_Ent
)));
2513 end Check_Component_Overlap
;
2515 -----------------------------------
2516 -- Check_Constant_Address_Clause --
2517 -----------------------------------
2519 procedure Check_Constant_Address_Clause
2523 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
2524 -- Checks that the given node N represents a name whose 'Address
2525 -- is constant (in the same sense as OK_Constant_Address_Clause,
2526 -- i.e. the address value is the same at the point of declaration
2527 -- of U_Ent and at the time of elaboration of the address clause.
2529 procedure Check_Expr_Constants
(Nod
: Node_Id
);
2530 -- Checks that Nod meets the requirements for a constant address
2531 -- clause in the sense of the enclosing procedure.
2533 procedure Check_List_Constants
(Lst
: List_Id
);
2534 -- Check that all elements of list Lst meet the requirements for a
2535 -- constant address clause in the sense of the enclosing procedure.
2537 -------------------------------
2538 -- Check_At_Constant_Address --
2539 -------------------------------
2541 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
2543 if Is_Entity_Name
(Nod
) then
2544 if Present
(Address_Clause
(Entity
((Nod
)))) then
2546 ("invalid address clause for initialized object &!",
2549 ("address for& cannot" &
2550 " depend on another address clause! ('R'M 13.1(22))!",
2553 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
2554 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
2557 ("invalid address clause for initialized object &!",
2559 Error_Msg_Name_1
:= Chars
(Entity
(Nod
));
2560 Error_Msg_Name_2
:= Chars
(U_Ent
);
2562 ("\% must be defined before % ('R'M 13.1(22))!",
2566 elsif Nkind
(Nod
) = N_Selected_Component
then
2568 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
2571 if (Is_Record_Type
(T
)
2572 and then Has_Discriminants
(T
))
2575 and then Is_Record_Type
(Designated_Type
(T
))
2576 and then Has_Discriminants
(Designated_Type
(T
)))
2579 ("invalid address clause for initialized object &!",
2582 ("\address cannot depend on component" &
2583 " of discriminated record ('R'M 13.1(22))!",
2586 Check_At_Constant_Address
(Prefix
(Nod
));
2590 elsif Nkind
(Nod
) = N_Indexed_Component
then
2591 Check_At_Constant_Address
(Prefix
(Nod
));
2592 Check_List_Constants
(Expressions
(Nod
));
2595 Check_Expr_Constants
(Nod
);
2597 end Check_At_Constant_Address
;
2599 --------------------------
2600 -- Check_Expr_Constants --
2601 --------------------------
2603 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
2604 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
2605 Ent
: Entity_Id
:= Empty
;
2608 if Nkind
(Nod
) in N_Has_Etype
2609 and then Etype
(Nod
) = Any_Type
2615 when N_Empty | N_Error
=>
2618 when N_Identifier | N_Expanded_Name
=>
2619 Ent
:= Entity
(Nod
);
2621 -- We need to look at the original node if it is different
2622 -- from the node, since we may have rewritten things and
2623 -- substituted an identifier representing the rewrite.
2625 if Original_Node
(Nod
) /= Nod
then
2626 Check_Expr_Constants
(Original_Node
(Nod
));
2628 -- If the node is an object declaration without initial
2629 -- value, some code has been expanded, and the expression
2630 -- is not constant, even if the constituents might be
2631 -- acceptable, as in A'Address + offset.
2633 if Ekind
(Ent
) = E_Variable
2634 and then Nkind
(Declaration_Node
(Ent
))
2635 = N_Object_Declaration
2637 No
(Expression
(Declaration_Node
(Ent
)))
2640 ("invalid address clause for initialized object &!",
2643 -- If entity is constant, it may be the result of expanding
2644 -- a check. We must verify that its declaration appears
2645 -- before the object in question, else we also reject the
2648 elsif Ekind
(Ent
) = E_Constant
2649 and then In_Same_Source_Unit
(Ent
, U_Ent
)
2650 and then Sloc
(Ent
) > Loc_U_Ent
2653 ("invalid address clause for initialized object &!",
2660 -- Otherwise look at the identifier and see if it is OK
2662 if Ekind
(Ent
) = E_Named_Integer
2664 Ekind
(Ent
) = E_Named_Real
2671 Ekind
(Ent
) = E_Constant
2673 Ekind
(Ent
) = E_In_Parameter
2675 -- This is the case where we must have Ent defined
2676 -- before U_Ent. Clearly if they are in different
2677 -- units this requirement is met since the unit
2678 -- containing Ent is already processed.
2680 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
2683 -- Otherwise location of Ent must be before the
2684 -- location of U_Ent, that's what prior defined means.
2686 elsif Sloc
(Ent
) < Loc_U_Ent
then
2691 ("invalid address clause for initialized object &!",
2693 Error_Msg_Name_1
:= Chars
(Ent
);
2694 Error_Msg_Name_2
:= Chars
(U_Ent
);
2696 ("\% must be defined before % ('R'M 13.1(22))!",
2700 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2701 Check_Expr_Constants
(Original_Node
(Nod
));
2705 ("invalid address clause for initialized object &!",
2708 if Comes_From_Source
(Ent
) then
2709 Error_Msg_Name_1
:= Chars
(Ent
);
2711 ("\reference to variable% not allowed"
2712 & " ('R'M 13.1(22))!", Nod
);
2715 ("non-static expression not allowed"
2716 & " ('R'M 13.1(22))!", Nod
);
2720 when N_Integer_Literal
=>
2722 -- If this is a rewritten unchecked conversion, in a system
2723 -- where Address is an integer type, always use the base type
2724 -- for a literal value. This is user-friendly and prevents
2725 -- order-of-elaboration issues with instances of unchecked
2728 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2729 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2732 when N_Real_Literal |
2734 N_Character_Literal
=>
2738 Check_Expr_Constants
(Low_Bound
(Nod
));
2739 Check_Expr_Constants
(High_Bound
(Nod
));
2741 when N_Explicit_Dereference
=>
2742 Check_Expr_Constants
(Prefix
(Nod
));
2744 when N_Indexed_Component
=>
2745 Check_Expr_Constants
(Prefix
(Nod
));
2746 Check_List_Constants
(Expressions
(Nod
));
2749 Check_Expr_Constants
(Prefix
(Nod
));
2750 Check_Expr_Constants
(Discrete_Range
(Nod
));
2752 when N_Selected_Component
=>
2753 Check_Expr_Constants
(Prefix
(Nod
));
2755 when N_Attribute_Reference
=>
2757 if Attribute_Name
(Nod
) = Name_Address
2759 Attribute_Name
(Nod
) = Name_Access
2761 Attribute_Name
(Nod
) = Name_Unchecked_Access
2763 Attribute_Name
(Nod
) = Name_Unrestricted_Access
2765 Check_At_Constant_Address
(Prefix
(Nod
));
2768 Check_Expr_Constants
(Prefix
(Nod
));
2769 Check_List_Constants
(Expressions
(Nod
));
2773 Check_List_Constants
(Component_Associations
(Nod
));
2774 Check_List_Constants
(Expressions
(Nod
));
2776 when N_Component_Association
=>
2777 Check_Expr_Constants
(Expression
(Nod
));
2779 when N_Extension_Aggregate
=>
2780 Check_Expr_Constants
(Ancestor_Part
(Nod
));
2781 Check_List_Constants
(Component_Associations
(Nod
));
2782 Check_List_Constants
(Expressions
(Nod
));
2787 when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In
=>
2788 Check_Expr_Constants
(Left_Opnd
(Nod
));
2789 Check_Expr_Constants
(Right_Opnd
(Nod
));
2792 Check_Expr_Constants
(Right_Opnd
(Nod
));
2794 when N_Type_Conversion |
2795 N_Qualified_Expression |
2797 Check_Expr_Constants
(Expression
(Nod
));
2799 when N_Unchecked_Type_Conversion
=>
2800 Check_Expr_Constants
(Expression
(Nod
));
2802 -- If this is a rewritten unchecked conversion, subtypes
2803 -- in this node are those created within the instance.
2804 -- To avoid order of elaboration issues, replace them
2805 -- with their base types. Note that address clauses can
2806 -- cause order of elaboration problems because they are
2807 -- elaborated by the back-end at the point of definition,
2808 -- and may mention entities declared in between (as long
2809 -- as everything is static). It is user-friendly to allow
2810 -- unchecked conversions in this context.
2812 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2813 Set_Etype
(Expression
(Nod
),
2814 Base_Type
(Etype
(Expression
(Nod
))));
2815 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2818 when N_Function_Call
=>
2819 if not Is_Pure
(Entity
(Name
(Nod
))) then
2821 ("invalid address clause for initialized object &!",
2825 ("\function & is not pure ('R'M 13.1(22))!",
2826 Nod
, Entity
(Name
(Nod
)));
2829 Check_List_Constants
(Parameter_Associations
(Nod
));
2832 when N_Parameter_Association
=>
2833 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
2837 ("invalid address clause for initialized object &!",
2840 ("\must be constant defined before& ('R'M 13.1(22))!",
2843 end Check_Expr_Constants
;
2845 --------------------------
2846 -- Check_List_Constants --
2847 --------------------------
2849 procedure Check_List_Constants
(Lst
: List_Id
) is
2853 if Present
(Lst
) then
2854 Nod1
:= First
(Lst
);
2855 while Present
(Nod1
) loop
2856 Check_Expr_Constants
(Nod1
);
2860 end Check_List_Constants
;
2862 -- Start of processing for Check_Constant_Address_Clause
2865 Check_Expr_Constants
(Expr
);
2866 end Check_Constant_Address_Clause
;
2872 procedure Check_Size
2876 Biased
: out Boolean)
2878 UT
: constant Entity_Id
:= Underlying_Type
(T
);
2884 -- Dismiss cases for generic types or types with previous errors
2887 or else UT
= Any_Type
2888 or else Is_Generic_Type
(UT
)
2889 or else Is_Generic_Type
(Root_Type
(UT
))
2893 -- Check case of bit packed array
2895 elsif Is_Array_Type
(UT
)
2896 and then Known_Static_Component_Size
(UT
)
2897 and then Is_Bit_Packed_Array
(UT
)
2905 Asiz
:= Component_Size
(UT
);
2906 Indx
:= First_Index
(UT
);
2908 Ityp
:= Etype
(Indx
);
2910 -- If non-static bound, then we are not in the business of
2911 -- trying to check the length, and indeed an error will be
2912 -- issued elsewhere, since sizes of non-static array types
2913 -- cannot be set implicitly or explicitly.
2915 if not Is_Static_Subtype
(Ityp
) then
2919 -- Otherwise accumulate next dimension
2921 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
2922 Expr_Value
(Type_Low_Bound
(Ityp
)) +
2926 exit when No
(Indx
);
2932 Error_Msg_Uint_1
:= Asiz
;
2934 ("size for& too small, minimum allowed is ^", N
, T
);
2935 Set_Esize
(T
, Asiz
);
2936 Set_RM_Size
(T
, Asiz
);
2940 -- All other composite types are ignored
2942 elsif Is_Composite_Type
(UT
) then
2945 -- For fixed-point types, don't check minimum if type is not frozen,
2946 -- since we don't know all the characteristics of the type that can
2947 -- affect the size (e.g. a specified small) till freeze time.
2949 elsif Is_Fixed_Point_Type
(UT
)
2950 and then not Is_Frozen
(UT
)
2954 -- Cases for which a minimum check is required
2957 -- Ignore if specified size is correct for the type
2959 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
2963 -- Otherwise get minimum size
2965 M
:= UI_From_Int
(Minimum_Size
(UT
));
2969 -- Size is less than minimum size, but one possibility remains
2970 -- that we can manage with the new size if we bias the type
2972 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
2975 Error_Msg_Uint_1
:= M
;
2977 ("size for& too small, minimum allowed is ^", N
, T
);
2987 -------------------------
2988 -- Get_Alignment_Value --
2989 -------------------------
2991 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
2992 Align
: constant Uint
:= Static_Integer
(Expr
);
2995 if Align
= No_Uint
then
2998 elsif Align
<= 0 then
2999 Error_Msg_N
("alignment value must be positive", Expr
);
3003 for J
in Int
range 0 .. 64 loop
3005 M
: constant Uint
:= Uint_2
** J
;
3008 exit when M
= Align
;
3012 ("alignment value must be power of 2", Expr
);
3020 end Get_Alignment_Value
;
3026 procedure Initialize
is
3028 Unchecked_Conversions
.Init
;
3031 -------------------------
3032 -- Is_Operational_Item --
3033 -------------------------
3035 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
3037 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
3041 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
3044 return Id
= Attribute_Input
3045 or else Id
= Attribute_Output
3046 or else Id
= Attribute_Read
3047 or else Id
= Attribute_Write
3048 or else Id
= Attribute_External_Tag
;
3051 end Is_Operational_Item
;
3053 --------------------------------------
3054 -- Mark_Aliased_Address_As_Volatile --
3055 --------------------------------------
3057 procedure Mark_Aliased_Address_As_Volatile
(N
: Node_Id
) is
3058 Ent
: constant Entity_Id
:= Address_Aliased_Entity
(N
);
3061 if Present
(Ent
) then
3062 Set_Treat_As_Volatile
(Ent
);
3064 end Mark_Aliased_Address_As_Volatile
;
3070 function Minimum_Size
3072 Biased
: Boolean := False) return Nat
3074 Lo
: Uint
:= No_Uint
;
3075 Hi
: Uint
:= No_Uint
;
3076 LoR
: Ureal
:= No_Ureal
;
3077 HiR
: Ureal
:= No_Ureal
;
3078 LoSet
: Boolean := False;
3079 HiSet
: Boolean := False;
3083 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
3086 -- If bad type, return 0
3088 if T
= Any_Type
then
3091 -- For generic types, just return zero. There cannot be any legitimate
3092 -- need to know such a size, but this routine may be called with a
3093 -- generic type as part of normal processing.
3095 elsif Is_Generic_Type
(R_Typ
)
3096 or else R_Typ
= Any_Type
3100 -- Access types. Normally an access type cannot have a size smaller
3101 -- than the size of System.Address. The exception is on VMS, where
3102 -- we have short and long addresses, and it is possible for an access
3103 -- type to have a short address size (and thus be less than the size
3104 -- of System.Address itself). We simply skip the check for VMS, and
3105 -- leave the back end to do the check.
3107 elsif Is_Access_Type
(T
) then
3108 if OpenVMS_On_Target
then
3111 return System_Address_Size
;
3114 -- Floating-point types
3116 elsif Is_Floating_Point_Type
(T
) then
3117 return UI_To_Int
(Esize
(R_Typ
));
3121 elsif Is_Discrete_Type
(T
) then
3123 -- The following loop is looking for the nearest compile time
3124 -- known bounds following the ancestor subtype chain. The idea
3125 -- is to find the most restrictive known bounds information.
3129 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
3134 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
3135 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
3142 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
3143 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
3149 Ancest
:= Ancestor_Subtype
(Ancest
);
3152 Ancest
:= Base_Type
(T
);
3154 if Is_Generic_Type
(Ancest
) then
3160 -- Fixed-point types. We can't simply use Expr_Value to get the
3161 -- Corresponding_Integer_Value values of the bounds, since these
3162 -- do not get set till the type is frozen, and this routine can
3163 -- be called before the type is frozen. Similarly the test for
3164 -- bounds being static needs to include the case where we have
3165 -- unanalyzed real literals for the same reason.
3167 elsif Is_Fixed_Point_Type
(T
) then
3169 -- The following loop is looking for the nearest compile time
3170 -- known bounds following the ancestor subtype chain. The idea
3171 -- is to find the most restrictive known bounds information.
3175 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
3180 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
3181 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
3183 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
3190 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
3191 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
3193 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
3199 Ancest
:= Ancestor_Subtype
(Ancest
);
3202 Ancest
:= Base_Type
(T
);
3204 if Is_Generic_Type
(Ancest
) then
3210 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
3211 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
3213 -- No other types allowed
3216 raise Program_Error
;
3219 -- Fall through with Hi and Lo set. Deal with biased case
3221 if (Biased
and then not Is_Fixed_Point_Type
(T
))
3222 or else Has_Biased_Representation
(T
)
3228 -- Signed case. Note that we consider types like range 1 .. -1 to be
3229 -- signed for the purpose of computing the size, since the bounds
3230 -- have to be accomodated in the base type.
3232 if Lo
< 0 or else Hi
< 0 then
3236 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3237 -- Note that we accommodate the case where the bounds cross. This
3238 -- can happen either because of the way the bounds are declared
3239 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3253 -- If both bounds are positive, make sure that both are represen-
3254 -- table in the case where the bounds are crossed. This can happen
3255 -- either because of the way the bounds are declared, or because of
3256 -- the algorithm in Freeze_Fixed_Point_Type.
3262 -- S = size, (can accommodate 0 .. (2**size - 1))
3265 while Hi
>= Uint_2
** S
loop
3273 -------------------------
3274 -- New_Stream_Function --
3275 -------------------------
3277 procedure New_Stream_Function
3281 Nam
: TSS_Name_Type
)
3283 Loc
: constant Source_Ptr
:= Sloc
(N
);
3284 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3285 Subp_Id
: Entity_Id
;
3286 Subp_Decl
: Node_Id
;
3290 function Build_Spec
return Node_Id
;
3291 -- Used for declaration and renaming declaration, so that this is
3292 -- treated as a renaming_as_body.
3298 function Build_Spec
return Node_Id
is
3300 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3303 Make_Function_Specification
(Loc
,
3304 Defining_Unit_Name
=> Subp_Id
,
3305 Parameter_Specifications
=>
3307 Make_Parameter_Specification
(Loc
,
3308 Defining_Identifier
=>
3309 Make_Defining_Identifier
(Loc
, Name_S
),
3311 Make_Access_Definition
(Loc
,
3314 Designated_Type
(Etype
(F
)), Loc
)))),
3317 New_Reference_To
(Etyp
, Loc
));
3320 -- Start of processing for New_Stream_Function
3323 F
:= First_Formal
(Subp
);
3324 Etyp
:= Etype
(Subp
);
3326 if not Is_Tagged_Type
(Ent
) then
3328 Make_Subprogram_Declaration
(Loc
,
3329 Specification
=> Build_Spec
);
3330 Insert_Action
(N
, Subp_Decl
);
3334 Make_Subprogram_Renaming_Declaration
(Loc
,
3335 Specification
=> Build_Spec
,
3336 Name
=> New_Reference_To
(Subp
, Loc
));
3338 if Is_Tagged_Type
(Ent
) and then not Is_Limited_Type
(Ent
) then
3339 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3341 Insert_Action
(N
, Subp_Decl
);
3342 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3344 end New_Stream_Function
;
3346 --------------------------
3347 -- New_Stream_Procedure --
3348 --------------------------
3350 procedure New_Stream_Procedure
3354 Nam
: TSS_Name_Type
;
3355 Out_P
: Boolean := False)
3357 Loc
: constant Source_Ptr
:= Sloc
(N
);
3358 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3359 Subp_Id
: Entity_Id
;
3360 Subp_Decl
: Node_Id
;
3364 function Build_Spec
return Node_Id
;
3365 -- Used for declaration and renaming declaration, so that this is
3366 -- treated as a renaming_as_body.
3372 function Build_Spec
return Node_Id
is
3374 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3377 Make_Procedure_Specification
(Loc
,
3378 Defining_Unit_Name
=> Subp_Id
,
3379 Parameter_Specifications
=>
3381 Make_Parameter_Specification
(Loc
,
3382 Defining_Identifier
=>
3383 Make_Defining_Identifier
(Loc
, Name_S
),
3385 Make_Access_Definition
(Loc
,
3388 Designated_Type
(Etype
(F
)), Loc
))),
3390 Make_Parameter_Specification
(Loc
,
3391 Defining_Identifier
=>
3392 Make_Defining_Identifier
(Loc
, Name_V
),
3393 Out_Present
=> Out_P
,
3395 New_Reference_To
(Etyp
, Loc
))));
3398 -- Start of processing for New_Stream_Procedure
3401 F
:= First_Formal
(Subp
);
3402 Etyp
:= Etype
(Next_Formal
(F
));
3404 if not Is_Tagged_Type
(Ent
) then
3406 Make_Subprogram_Declaration
(Loc
,
3407 Specification
=> Build_Spec
);
3408 Insert_Action
(N
, Subp_Decl
);
3412 Make_Subprogram_Renaming_Declaration
(Loc
,
3413 Specification
=> Build_Spec
,
3414 Name
=> New_Reference_To
(Subp
, Loc
));
3416 if Is_Tagged_Type
(Ent
) and then not Is_Limited_Type
(Ent
) then
3417 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3419 Insert_Action
(N
, Subp_Decl
);
3420 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3422 end New_Stream_Procedure
;
3424 ------------------------
3425 -- Rep_Item_Too_Early --
3426 ------------------------
3428 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
3430 -- Cannot apply rep items that are not operational items
3433 if Is_Operational_Item
(N
) then
3437 and then Is_Generic_Type
(Root_Type
(T
))
3440 ("representation item not allowed for generic type", N
);
3444 -- Otherwise check for incompleted type
3446 if Is_Incomplete_Or_Private_Type
(T
)
3447 and then No
(Underlying_Type
(T
))
3450 ("representation item must be after full type declaration", N
);
3453 -- If the type has incompleted components, a representation clause is
3454 -- illegal but stream attributes and Convention pragmas are correct.
3456 elsif Has_Private_Component
(T
) then
3457 if Nkind
(N
) = N_Pragma
then
3461 ("representation item must appear after type is fully defined",
3468 end Rep_Item_Too_Early
;
3470 -----------------------
3471 -- Rep_Item_Too_Late --
3472 -----------------------
3474 function Rep_Item_Too_Late
3477 FOnly
: Boolean := False) return Boolean
3480 Parent_Type
: Entity_Id
;
3483 -- Output the too late message. Note that this is not considered a
3484 -- serious error, since the effect is simply that we ignore the
3485 -- representation clause in this case.
3491 procedure Too_Late
is
3493 Error_Msg_N
("|representation item appears too late!", N
);
3496 -- Start of processing for Rep_Item_Too_Late
3499 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3500 -- types, which may be frozen if they appear in a representation clause
3501 -- for a local type.
3504 and then not From_With_Type
(T
)
3507 S
:= First_Subtype
(T
);
3509 if Present
(Freeze_Node
(S
)) then
3511 ("?no more representation items for }!", Freeze_Node
(S
), S
);
3516 -- Check for case of non-tagged derived type whose parent either has
3517 -- primitive operations, or is a by reference type (RM 13.1(10)).
3521 and then Is_Derived_Type
(T
)
3522 and then not Is_Tagged_Type
(T
)
3524 Parent_Type
:= Etype
(Base_Type
(T
));
3526 if Has_Primitive_Operations
(Parent_Type
) then
3529 ("primitive operations already defined for&!", N
, Parent_Type
);
3532 elsif Is_By_Reference_Type
(Parent_Type
) then
3535 ("parent type & is a by reference type!", N
, Parent_Type
);
3540 -- No error, link item into head of chain of rep items for the entity
3542 Record_Rep_Item
(T
, N
);
3544 end Rep_Item_Too_Late
;
3546 -------------------------
3547 -- Same_Representation --
3548 -------------------------
3550 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
3551 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
3552 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
3555 -- A quick check, if base types are the same, then we definitely have
3556 -- the same representation, because the subtype specific representation
3557 -- attributes (Size and Alignment) do not affect representation from
3558 -- the point of view of this test.
3560 if Base_Type
(T1
) = Base_Type
(T2
) then
3563 elsif Is_Private_Type
(Base_Type
(T2
))
3564 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
3569 -- Tagged types never have differing representations
3571 if Is_Tagged_Type
(T1
) then
3575 -- Representations are definitely different if conventions differ
3577 if Convention
(T1
) /= Convention
(T2
) then
3581 -- Representations are different if component alignments differ
3583 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
3585 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
3586 and then Component_Alignment
(T1
) /= Component_Alignment
(T2
)
3591 -- For arrays, the only real issue is component size. If we know the
3592 -- component size for both arrays, and it is the same, then that's
3593 -- good enough to know we don't have a change of representation.
3595 if Is_Array_Type
(T1
) then
3596 if Known_Component_Size
(T1
)
3597 and then Known_Component_Size
(T2
)
3598 and then Component_Size
(T1
) = Component_Size
(T2
)
3604 -- Types definitely have same representation if neither has non-standard
3605 -- representation since default representations are always consistent.
3606 -- If only one has non-standard representation, and the other does not,
3607 -- then we consider that they do not have the same representation. They
3608 -- might, but there is no way of telling early enough.
3610 if Has_Non_Standard_Rep
(T1
) then
3611 if not Has_Non_Standard_Rep
(T2
) then
3615 return not Has_Non_Standard_Rep
(T2
);
3618 -- Here the two types both have non-standard representation, and we
3619 -- need to determine if they have the same non-standard representation
3621 -- For arrays, we simply need to test if the component sizes are the
3622 -- same. Pragma Pack is reflected in modified component sizes, so this
3623 -- check also deals with pragma Pack.
3625 if Is_Array_Type
(T1
) then
3626 return Component_Size
(T1
) = Component_Size
(T2
);
3628 -- Tagged types always have the same representation, because it is not
3629 -- possible to specify different representations for common fields.
3631 elsif Is_Tagged_Type
(T1
) then
3634 -- Case of record types
3636 elsif Is_Record_Type
(T1
) then
3638 -- Packed status must conform
3640 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
3643 -- Otherwise we must check components. Typ2 maybe a constrained
3644 -- subtype with fewer components, so we compare the components
3645 -- of the base types.
3648 Record_Case
: declare
3649 CD1
, CD2
: Entity_Id
;
3651 function Same_Rep
return Boolean;
3652 -- CD1 and CD2 are either components or discriminants. This
3653 -- function tests whether the two have the same representation
3659 function Same_Rep
return Boolean is
3661 if No
(Component_Clause
(CD1
)) then
3662 return No
(Component_Clause
(CD2
));
3666 Present
(Component_Clause
(CD2
))
3668 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
3670 Esize
(CD1
) = Esize
(CD2
);
3674 -- Start processing for Record_Case
3677 if Has_Discriminants
(T1
) then
3678 CD1
:= First_Discriminant
(T1
);
3679 CD2
:= First_Discriminant
(T2
);
3681 -- The number of discriminants may be different if the
3682 -- derived type has fewer (constrained by values). The
3683 -- invisible discriminants retain the representation of
3684 -- the original, so the discrepancy does not per se
3685 -- indicate a different representation.
3688 and then Present
(CD2
)
3690 if not Same_Rep
then
3693 Next_Discriminant
(CD1
);
3694 Next_Discriminant
(CD2
);
3699 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
3700 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
3702 while Present
(CD1
) loop
3703 if not Same_Rep
then
3706 Next_Component
(CD1
);
3707 Next_Component
(CD2
);
3715 -- For enumeration types, we must check each literal to see if the
3716 -- representation is the same. Note that we do not permit enumeration
3717 -- reprsentation clauses for Character and Wide_Character, so these
3718 -- cases were already dealt with.
3720 elsif Is_Enumeration_Type
(T1
) then
3722 Enumeration_Case
: declare
3726 L1
:= First_Literal
(T1
);
3727 L2
:= First_Literal
(T2
);
3729 while Present
(L1
) loop
3730 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
3740 end Enumeration_Case
;
3742 -- Any other types have the same representation for these purposes
3747 end Same_Representation
;
3749 --------------------
3750 -- Set_Enum_Esize --
3751 --------------------
3753 procedure Set_Enum_Esize
(T
: Entity_Id
) is
3761 -- Find the minimum standard size (8,16,32,64) that fits
3763 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
3764 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
3767 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
3768 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3770 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
3773 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
3776 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
3781 if Hi
< Uint_2
**08 then
3782 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3784 elsif Hi
< Uint_2
**16 then
3787 elsif Hi
< Uint_2
**32 then
3790 else pragma Assert
(Hi
< Uint_2
**63);
3795 -- That minimum is the proper size unless we have a foreign convention
3796 -- and the size required is 32 or less, in which case we bump the size
3797 -- up to 32. This is required for C and C++ and seems reasonable for
3798 -- all other foreign conventions.
3800 if Has_Foreign_Convention
(T
)
3801 and then Esize
(T
) < Standard_Integer_Size
3803 Init_Esize
(T
, Standard_Integer_Size
);
3810 -----------------------------------
3811 -- Validate_Unchecked_Conversion --
3812 -----------------------------------
3814 procedure Validate_Unchecked_Conversion
3816 Act_Unit
: Entity_Id
)
3823 -- Obtain source and target types. Note that we call Ancestor_Subtype
3824 -- here because the processing for generic instantiation always makes
3825 -- subtypes, and we want the original frozen actual types.
3827 -- If we are dealing with private types, then do the check on their
3828 -- fully declared counterparts if the full declarations have been
3829 -- encountered (they don't have to be visible, but they must exist!)
3831 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
3833 if Is_Private_Type
(Source
)
3834 and then Present
(Underlying_Type
(Source
))
3836 Source
:= Underlying_Type
(Source
);
3839 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
3841 -- If either type is generic, the instantiation happens within a
3842 -- generic unit, and there is nothing to check. The proper check
3843 -- will happen when the enclosing generic is instantiated.
3845 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
3849 if Is_Private_Type
(Target
)
3850 and then Present
(Underlying_Type
(Target
))
3852 Target
:= Underlying_Type
(Target
);
3855 -- Source may be unconstrained array, but not target
3857 if Is_Array_Type
(Target
)
3858 and then not Is_Constrained
(Target
)
3861 ("unchecked conversion to unconstrained array not allowed", N
);
3865 -- Make entry in unchecked conversion table for later processing
3866 -- by Validate_Unchecked_Conversions, which will check sizes and
3867 -- alignments (using values set by the back-end where possible).
3868 -- This is only done if the appropriate warning is active
3870 if Warn_On_Unchecked_Conversion
then
3871 Unchecked_Conversions
.Append
3872 (New_Val
=> UC_Entry
'
3877 -- If both sizes are known statically now, then back end annotation
3878 -- is not required to do a proper check but if either size is not
3879 -- known statically, then we need the annotation.
3881 if Known_Static_RM_Size (Source)
3882 and then Known_Static_RM_Size (Target)
3886 Back_Annotate_Rep_Info := True;
3890 -- If unchecked conversion to access type, and access type is
3891 -- declared in the same unit as the unchecked conversion, then
3892 -- set the No_Strict_Aliasing flag (no strict aliasing is
3893 -- implicit in this situation).
3895 if Is_Access_Type (Target) and then
3896 In_Same_Source_Unit (Target, N)
3898 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
3901 -- Generate N_Validate_Unchecked_Conversion node for back end in
3902 -- case the back end needs to perform special validation checks.
3904 -- Shouldn't this be in exp_ch13, since the check only gets done
3905 -- if we have full expansion and the back end is called ???
3908 Make_Validate_Unchecked_Conversion (Sloc (N));
3909 Set_Source_Type (Vnode, Source);
3910 Set_Target_Type (Vnode, Target);
3912 -- If the unchecked conversion node is in a list, just insert before
3913 -- it. If not we have some strange case, not worth bothering about.
3915 if Is_List_Member (N) then
3916 Insert_After (N, Vnode);
3918 end Validate_Unchecked_Conversion;
3920 ------------------------------------
3921 -- Validate_Unchecked_Conversions --
3922 ------------------------------------
3924 procedure Validate_Unchecked_Conversions is
3926 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
3928 T : UC_Entry renames Unchecked_Conversions.Table (N);
3930 Enode : constant Node_Id := T.Enode;
3931 Source : constant Entity_Id := T.Source;
3932 Target : constant Entity_Id := T.Target;
3938 -- This validation check, which warns if we have unequal sizes
3939 -- for unchecked conversion, and thus potentially implementation
3940 -- dependent semantics, is one of the few occasions on which we
3941 -- use the official RM size instead of Esize. See description
3942 -- in Einfo "Handling of Type'Size Values" for details.
3944 if Serious_Errors_Detected = 0
3945 and then Known_Static_RM_Size (Source)
3946 and then Known_Static_RM_Size (Target)
3948 Source_Siz := RM_Size (Source);
3949 Target_Siz := RM_Size (Target);
3951 if Source_Siz /= Target_Siz then
3953 ("types for unchecked conversion have different sizes?",
3956 if All_Errors_Mode then
3957 Error_Msg_Name_1 := Chars (Source);
3958 Error_Msg_Uint_1 := Source_Siz;
3959 Error_Msg_Name_2 := Chars (Target);
3960 Error_Msg_Uint_2 := Target_Siz;
3962 ("\size of % is ^, size of % is ^?", Enode);
3964 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
3966 if Is_Discrete_Type (Source)
3967 and then Is_Discrete_Type (Target)
3969 if Source_Siz > Target_Siz then
3971 ("\^ high order bits of source will be ignored?",
3974 elsif Is_Unsigned_Type (Source) then
3976 ("\source will be extended with ^ high order " &
3977 "zero bits?", Enode);
3981 ("\source will be extended with ^ high order " &
3986 elsif Source_Siz < Target_Siz then
3987 if Is_Discrete_Type (Target) then
3988 if Bytes_Big_Endian then
3990 ("\target value will include ^ undefined " &
3995 ("\target value will include ^ undefined " &
4002 ("\^ trailing bits of target value will be " &
4003 "undefined?", Enode);
4006 else pragma Assert (Source_Siz > Target_Siz);
4008 ("\^ trailing bits of source will be ignored?",
4015 -- If both types are access types, we need to check the alignment.
4016 -- If the alignment of both is specified, we can do it here.
4018 if Serious_Errors_Detected = 0
4019 and then Ekind (Source) in Access_Kind
4020 and then Ekind (Target) in Access_Kind
4021 and then Target_Strict_Alignment
4022 and then Present (Designated_Type (Source))
4023 and then Present (Designated_Type (Target))
4026 D_Source : constant Entity_Id := Designated_Type (Source);
4027 D_Target : constant Entity_Id := Designated_Type (Target);
4030 if Known_Alignment (D_Source)
4031 and then Known_Alignment (D_Target)
4034 Source_Align : constant Uint := Alignment (D_Source);
4035 Target_Align : constant Uint := Alignment (D_Target);
4038 if Source_Align < Target_Align
4039 and then not Is_Tagged_Type (D_Source)
4041 Error_Msg_Uint_1 := Target_Align;
4042 Error_Msg_Uint_2 := Source_Align;
4043 Error_Msg_Node_2 := D_Source;
4045 ("alignment of & (^) is stricter than " &
4046 "alignment of & (^)?", Enode, D_Target);
4048 if All_Errors_Mode then
4050 ("\resulting access value may have invalid " &
4051 "alignment?", Enode);
4060 end Validate_Unchecked_Conversions;