1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Exp_Tss
; use Exp_Tss
;
33 with Exp_Util
; use Exp_Util
;
34 with Hostparm
; use Hostparm
;
36 with Nlists
; use Nlists
;
37 with Nmake
; use Nmake
;
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 Ttypes
; use Ttypes
;
51 with Tbuild
; use Tbuild
;
52 with Urealp
; use Urealp
;
54 with GNAT
.Heap_Sort_A
; use GNAT
.Heap_Sort_A
;
56 package body Sem_Ch13
is
58 SSU
: constant Pos
:= System_Storage_Unit
;
59 -- Convenient short hand for commonly used constant
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 procedure Alignment_Check_For_Esize_Change
(Typ
: Entity_Id
);
66 -- This routine is called after setting the Esize of type entity Typ.
67 -- The purpose is to deal with the situation where an aligment has been
68 -- inherited from a derived type that is no longer appropriate for the
69 -- new Esize value. In this case, we reset the Alignment to unknown.
71 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
72 -- Given two entities for record components or discriminants, checks
73 -- if they hav overlapping component clauses and issues errors if so.
75 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
76 -- Given the expression for an alignment value, returns the corresponding
77 -- Uint value. If the value is inappropriate, then error messages are
78 -- posted as required, and a value of No_Uint is returned.
80 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
81 -- A specification for a stream attribute is allowed before the full
82 -- type is declared, as explained in AI-00137 and the corrigendum.
83 -- Attributes that do not specify a representation characteristic are
84 -- operational attributes.
86 procedure New_Stream_Function
91 -- Create a function renaming of a given stream attribute to the
92 -- designated subprogram and then in the tagged case, provide this as
93 -- a primitive operation, or in the non-tagged case make an appropriate
94 -- TSS entry. Used for Input. This is more properly an expansion activity
95 -- than just semantics, but the presence of user-defined stream functions
96 -- for limited types is a legality check, which is why this takes place
97 -- here rather than in exp_ch13, where it was previously.
99 -- To avoid elaboration anomalies with freeze nodes, for untagged types
100 -- we generate both a subprogram declaration and a subprogram renaming
101 -- declaration, so that the attribute specification is handled as a
102 -- renaming_as_body. For tagged types, the specification is one of the
105 procedure New_Stream_Procedure
110 Out_P
: Boolean := False);
111 -- Create a procedure renaming of a given stream attribute to the
112 -- designated subprogram and then in the tagged case, provide this as
113 -- a primitive operation, or in the non-tagged case make an appropriate
114 -- TSS entry. Used for Read, Output, Write.
116 procedure Check_Constant_Address_Clause
(Expr
: Node_Id
; U_Ent
: Entity_Id
);
117 -- Expr is an expression for an address clause. This procedure checks
118 -- that the expression is constant, in the limited sense that it is safe
119 -- to evaluate it at the point the object U_Ent is declared, rather than
120 -- at the point of the address clause. The condition for this to be true
121 -- is that the expression has no variables, no constants declared after
122 -- U_Ent, and no calls to non-pure functions. If this condition is not
123 -- met, then an appropriate error message is posted.
125 procedure Warn_Overlay
129 -- Expr is the expression for an address clause for entity Nam whose type
130 -- is Typ. If Typ has a default initialization, check whether the address
131 -- clause might overlay two entities, and emit a warning on the side effect
132 -- that the initialization will cause.
134 ----------------------------------------------
135 -- Table for Validate_Unchecked_Conversions --
136 ----------------------------------------------
138 -- The following table collects unchecked conversions for validation.
139 -- Entries are made by Validate_Unchecked_Conversion and then the
140 -- call to Validate_Unchecked_Conversions does the actual error
141 -- checking and posting of warnings. The reason for this delayed
142 -- processing is to take advantage of back-annotations of size and
143 -- alignment values peformed by the back end.
145 type UC_Entry
is record
146 Enode
: Node_Id
; -- node used for posting warnings
147 Source
: Entity_Id
; -- source type for unchecked conversion
148 Target
: Entity_Id
; -- target type for unchecked conversion
151 package Unchecked_Conversions
is new Table
.Table
(
152 Table_Component_Type
=> UC_Entry
,
153 Table_Index_Type
=> Int
,
154 Table_Low_Bound
=> 1,
156 Table_Increment
=> 200,
157 Table_Name
=> "Unchecked_Conversions");
159 --------------------------------------
160 -- Alignment_Check_For_Esize_Change --
161 --------------------------------------
163 procedure Alignment_Check_For_Esize_Change
(Typ
: Entity_Id
) is
165 -- If the alignment is known, and not set by a rep clause, and is
166 -- inconsistent with the size being set, then reset it to unknown,
167 -- we assume in this case that the size overrides the inherited
168 -- alignment, and that the alignment must be recomputed.
170 if Known_Alignment
(Typ
)
171 and then not Has_Alignment_Clause
(Typ
)
172 and then Esize
(Typ
) mod (Alignment
(Typ
) * SSU
) /= 0
174 Init_Alignment
(Typ
);
176 end Alignment_Check_For_Esize_Change
;
178 -----------------------
179 -- Analyze_At_Clause --
180 -----------------------
182 -- An at clause is replaced by the corresponding Address attribute
183 -- definition clause that is the preferred approach in Ada 95.
185 procedure Analyze_At_Clause
(N
: Node_Id
) is
188 Make_Attribute_Definition_Clause
(Sloc
(N
),
189 Name
=> Identifier
(N
),
190 Chars
=> Name_Address
,
191 Expression
=> Expression
(N
)));
192 Analyze_Attribute_Definition_Clause
(N
);
193 end Analyze_At_Clause
;
195 -----------------------------------------
196 -- Analyze_Attribute_Definition_Clause --
197 -----------------------------------------
199 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
200 Loc
: constant Source_Ptr
:= Sloc
(N
);
201 Nam
: constant Node_Id
:= Name
(N
);
202 Attr
: constant Name_Id
:= Chars
(N
);
203 Expr
: constant Node_Id
:= Expression
(N
);
204 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
208 FOnly
: Boolean := False;
209 -- Reset to True for subtype specific attribute (Alignment, Size)
210 -- and for stream attributes, i.e. those cases where in the call
211 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
212 -- rules are checked. Note that the case of stream attributes is not
213 -- clear from the RM, but see AI95-00137. Also, the RM seems to
214 -- disallow Storage_Size for derived task types, but that is also
215 -- clearly unintentional.
221 if Rep_Item_Too_Early
(Ent
, N
) then
225 -- Rep clause applies to full view of incomplete type or private type
226 -- if we have one (if not, this is a premature use of the type).
227 -- However, certain semantic checks need to be done on the specified
228 -- entity (i.e. the private view), so we save it in Ent.
230 if Is_Private_Type
(Ent
)
231 and then Is_Derived_Type
(Ent
)
232 and then not Is_Tagged_Type
(Ent
)
233 and then No
(Full_View
(Ent
))
235 -- If this is a private type whose completion is a derivation
236 -- from another private type, there is no full view, and the
237 -- attribute belongs to the type itself, not its underlying parent.
241 elsif Ekind
(Ent
) = E_Incomplete_Type
then
242 Ent
:= Underlying_Type
(Ent
);
245 U_Ent
:= Underlying_Type
(Ent
);
248 -- Complete other routine error checks
250 if Etype
(Nam
) = Any_Type
then
253 elsif Scope
(Ent
) /= Current_Scope
then
254 Error_Msg_N
("entity must be declared in this scope", Nam
);
257 elsif No
(U_Ent
) then
260 elsif Is_Type
(U_Ent
)
261 and then not Is_First_Subtype
(U_Ent
)
262 and then Id
/= Attribute_Object_Size
263 and then Id
/= Attribute_Value_Size
264 and then not From_At_Mod
(N
)
266 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
271 -- Switch on particular attribute
279 -- Address attribute definition clause
281 when Attribute_Address
=> Address
: begin
282 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
284 if Present
(Address_Clause
(U_Ent
)) then
285 Error_Msg_N
("address already given for &", Nam
);
287 -- Case of address clause for subprogram
289 elsif Is_Subprogram
(U_Ent
) then
291 if Has_Homonym
(U_Ent
) then
293 ("address clause cannot be given " &
294 "for overloaded subprogram",
298 -- For subprograms, all address clauses are permitted,
299 -- and we mark the subprogram as having a deferred freeze
300 -- so that Gigi will not elaborate it too soon.
302 -- Above needs more comments, what is too soon about???
304 Set_Has_Delayed_Freeze
(U_Ent
);
306 -- Case of address clause for entry
308 elsif Ekind
(U_Ent
) = E_Entry
then
310 if Nkind
(Parent
(N
)) = N_Task_Body
then
312 ("entry address must be specified in task spec", Nam
);
315 -- For entries, we require a constant address
317 Check_Constant_Address_Clause
(Expr
, U_Ent
);
319 if Is_Task_Type
(Scope
(U_Ent
))
320 and then Comes_From_Source
(Scope
(U_Ent
))
323 ("?entry address declared for entry in task type", N
);
325 ("\?only one task can be declared of this type", N
);
328 -- Case of address clause for an object
331 Ekind
(U_Ent
) = E_Variable
333 Ekind
(U_Ent
) = E_Constant
336 Decl
: constant Node_Id
:= Declaration_Node
(U_Ent
);
337 Expr
: constant Node_Id
:= Expression
(N
);
338 Typ
: constant Entity_Id
:= Etype
(U_Ent
);
341 -- Exported variables cannot have an address clause,
342 -- because this cancels the effect of the pragma Export
344 if Is_Exported
(U_Ent
) then
346 ("cannot export object with address clause", Nam
);
348 -- Imported variables can have an address clause, but then
349 -- the import is pretty meaningless except to suppress
350 -- initializations, so we do not need such variables to
351 -- be statically allocated (and in fact it causes trouble
352 -- if the address clause is a local value).
354 elsif Is_Imported
(U_Ent
) then
355 Set_Is_Statically_Allocated
(U_Ent
, False);
358 -- We mark a possible modification of a variable with an
359 -- address clause, since it is likely aliasing is occurring.
361 Note_Possible_Modification
(Nam
);
363 -- If we have no initialization of any kind, then we can
364 -- safely defer the elaboration of the variable to its
365 -- freezing point, so that the address clause will be
366 -- computed at the proper point.
368 -- The same processing applies to all initialized scalar
369 -- types and all access types. Packed bit arrays of size
370 -- up to 64 are represented using a modular type with an
371 -- initialization (to zero) and can be processed like
372 -- other initialized scalar types.
374 if (No
(Expression
(Decl
))
375 and then not Has_Non_Null_Base_Init_Proc
(Typ
))
378 (Present
(Expression
(Decl
))
379 and then Is_Scalar_Type
(Typ
))
385 (Is_Bit_Packed_Array
(Base_Type
(Typ
))
387 Is_Modular_Integer_Type
(Packed_Array_Type
(Typ
)))
389 Set_Has_Delayed_Freeze
(U_Ent
);
391 -- Otherwise, we require the address clause to be constant
394 Check_Constant_Address_Clause
(Expr
, U_Ent
);
397 if Is_Exported
(U_Ent
) then
399 ("& cannot be exported if an address clause is given",
402 ("\define and export a variable " &
403 "that holds its address instead",
407 if not Error_Posted
(Expr
) then
408 Warn_Overlay
(Expr
, Typ
, Nam
);
411 -- If entity has delayed freeze then we will generate
412 -- an alignment check at the freeze point. If there is
413 -- no delayed freeze we can do it right now.
415 if not Has_Delayed_Freeze
(U_Ent
) then
416 Apply_Alignment_Check
(U_Ent
, N
);
419 -- Kill the size check code, since we are not allocating
420 -- the variable, it is somewhere else.
422 Kill_Size_Check_Code
(U_Ent
);
425 -- Not a valid entity for an address clause
428 Error_Msg_N
("address cannot be given for &", Nam
);
436 -- Alignment attribute definition clause
438 when Attribute_Alignment
=> Alignment_Block
: declare
439 Align
: Uint
:= Get_Alignment_Value
(Expr
);
444 if not Is_Type
(U_Ent
)
445 and then Ekind
(U_Ent
) /= E_Variable
446 and then Ekind
(U_Ent
) /= E_Constant
448 Error_Msg_N
("alignment cannot be given for &", Nam
);
450 elsif Has_Alignment_Clause
(U_Ent
) then
451 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
452 Error_Msg_N
("alignment clause previously given#", N
);
454 elsif Align
/= No_Uint
then
455 Set_Has_Alignment_Clause
(U_Ent
);
456 Set_Alignment
(U_Ent
, Align
);
464 -- Bit_Order attribute definition clause
466 when Attribute_Bit_Order
=> Bit_Order
: declare
468 if not Is_Record_Type
(U_Ent
) then
470 ("Bit_Order can only be defined for record type", Nam
);
473 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
475 if Etype
(Expr
) = Any_Type
then
478 elsif not Is_Static_Expression
(Expr
) then
479 Error_Msg_N
("Bit_Order requires static expression", Expr
);
482 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
483 Set_Reverse_Bit_Order
(U_Ent
, True);
493 -- Component_Size attribute definition clause
495 when Attribute_Component_Size
=> Component_Size_Case
: declare
496 Csize
: constant Uint
:= Static_Integer
(Expr
);
499 New_Ctyp
: Entity_Id
;
503 if not Is_Array_Type
(U_Ent
) then
504 Error_Msg_N
("component size requires array type", Nam
);
508 Btype
:= Base_Type
(U_Ent
);
510 if Has_Component_Size_Clause
(Btype
) then
512 ("component size clase for& previously given", Nam
);
514 elsif Csize
/= No_Uint
then
515 Check_Size
(Expr
, Component_Type
(Btype
), Csize
, Biased
);
517 if Has_Aliased_Components
(Btype
)
523 ("component size incorrect for aliased components", N
);
527 -- For the biased case, build a declaration for a subtype
528 -- that will be used to represent the biased subtype that
529 -- reflects the biased representation of components. We need
530 -- this subtype to get proper conversions on referencing
531 -- elements of the array.
535 Make_Defining_Identifier
(Loc
,
536 Chars
=> New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
539 Make_Subtype_Declaration
(Loc
,
540 Defining_Identifier
=> New_Ctyp
,
541 Subtype_Indication
=>
542 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
544 Set_Parent
(Decl
, N
);
545 Analyze
(Decl
, Suppress
=> All_Checks
);
547 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
548 Set_Esize
(New_Ctyp
, Csize
);
549 Set_RM_Size
(New_Ctyp
, Csize
);
550 Init_Alignment
(New_Ctyp
);
551 Set_Has_Biased_Representation
(New_Ctyp
, True);
552 Set_Is_Itype
(New_Ctyp
, True);
553 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
555 Set_Component_Type
(Btype
, New_Ctyp
);
558 Set_Component_Size
(Btype
, Csize
);
559 Set_Has_Component_Size_Clause
(Btype
, True);
560 Set_Has_Non_Standard_Rep
(Btype
, True);
562 end Component_Size_Case
;
568 when Attribute_External_Tag
=> External_Tag
:
570 if not Is_Tagged_Type
(U_Ent
) then
571 Error_Msg_N
("should be a tagged type", Nam
);
574 Analyze_And_Resolve
(Expr
, Standard_String
);
576 if not Is_Static_Expression
(Expr
) then
577 Error_Msg_N
("must be a static string", Nam
);
580 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
587 when Attribute_Input
=> Input
: declare
588 Subp
: Entity_Id
:= Empty
;
593 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
594 -- Return true if the entity is a function with an appropriate
595 -- profile for the Input attribute.
597 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
599 Ok
: Boolean := False;
602 if Ekind
(Subp
) = E_Function
then
603 F
:= First_Formal
(Subp
);
605 if Present
(F
) and then No
(Next_Formal
(F
)) then
606 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
608 Designated_Type
(Etype
(F
)) =
609 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
611 Ok
:= Base_Type
(Etype
(Subp
)) = Base_Type
(Ent
);
617 end Has_Good_Profile
;
619 -- Start of processing for Input attribute definition
624 if not Is_Type
(U_Ent
) then
625 Error_Msg_N
("local name must be a subtype", Nam
);
629 Pnam
:= TSS
(Base_Type
(U_Ent
), Name_uInput
);
632 and then Base_Type
(Etype
(Pnam
)) = Base_Type
(U_Ent
)
634 Error_Msg_Sloc
:= Sloc
(Pnam
);
635 Error_Msg_N
("input attribute already defined #", Nam
);
642 if Is_Entity_Name
(Expr
) then
643 if not Is_Overloaded
(Expr
) then
644 if Has_Good_Profile
(Entity
(Expr
)) then
645 Subp
:= Entity
(Expr
);
649 Get_First_Interp
(Expr
, I
, It
);
651 while Present
(It
.Nam
) loop
652 if Has_Good_Profile
(It
.Nam
) then
657 Get_Next_Interp
(I
, It
);
662 if Present
(Subp
) then
663 Set_Entity
(Expr
, Subp
);
664 Set_Etype
(Expr
, Etype
(Subp
));
665 New_Stream_Function
(N
, U_Ent
, Subp
, Name_uInput
);
667 Error_Msg_N
("incorrect expression for input attribute", Expr
);
676 -- Machine radix attribute definition clause
678 when Attribute_Machine_Radix
=> Machine_Radix
: declare
679 Radix
: constant Uint
:= Static_Integer
(Expr
);
682 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
683 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
685 elsif Has_Machine_Radix_Clause
(U_Ent
) then
686 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
687 Error_Msg_N
("machine radix clause previously given#", N
);
689 elsif Radix
/= No_Uint
then
690 Set_Has_Machine_Radix_Clause
(U_Ent
);
691 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
695 elsif Radix
= 10 then
696 Set_Machine_Radix_10
(U_Ent
);
698 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
707 -- Object_Size attribute definition clause
709 when Attribute_Object_Size
=> Object_Size
: declare
710 Size
: constant Uint
:= Static_Integer
(Expr
);
714 if not Is_Type
(U_Ent
) then
715 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
717 elsif Has_Object_Size_Clause
(U_Ent
) then
718 Error_Msg_N
("Object_Size already given for &", Nam
);
721 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
729 UI_Mod
(Size
, 64) /= 0
732 ("Object_Size must be 8, 16, 32, or multiple of 64",
736 Set_Esize
(U_Ent
, Size
);
737 Set_Has_Object_Size_Clause
(U_Ent
);
738 Alignment_Check_For_Esize_Change
(U_Ent
);
746 when Attribute_Output
=> Output
: declare
747 Subp
: Entity_Id
:= Empty
;
752 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
753 -- Return true if the entity is a procedure with an
754 -- appropriate profile for the output attribute.
756 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
758 Ok
: Boolean := False;
761 if Ekind
(Subp
) = E_Procedure
then
762 F
:= First_Formal
(Subp
);
765 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
767 Designated_Type
(Etype
(F
)) =
768 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
772 and then Parameter_Mode
(F
) = E_In_Parameter
773 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
774 and then No
(Next_Formal
(F
));
780 end Has_Good_Profile
;
785 if not Is_Type
(U_Ent
) then
786 Error_Msg_N
("local name must be a subtype", Nam
);
790 Pnam
:= TSS
(Base_Type
(U_Ent
), Name_uOutput
);
794 Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
797 Error_Msg_Sloc
:= Sloc
(Pnam
);
798 Error_Msg_N
("output attribute already defined #", Nam
);
805 if Is_Entity_Name
(Expr
) then
806 if not Is_Overloaded
(Expr
) then
807 if Has_Good_Profile
(Entity
(Expr
)) then
808 Subp
:= Entity
(Expr
);
812 Get_First_Interp
(Expr
, I
, It
);
814 while Present
(It
.Nam
) loop
815 if Has_Good_Profile
(It
.Nam
) then
820 Get_Next_Interp
(I
, It
);
825 if Present
(Subp
) then
826 Set_Entity
(Expr
, Subp
);
827 Set_Etype
(Expr
, Etype
(Subp
));
828 New_Stream_Procedure
(N
, U_Ent
, Subp
, Name_uOutput
);
830 Error_Msg_N
("incorrect expression for output attribute", Expr
);
839 when Attribute_Read
=> Read
: declare
840 Subp
: Entity_Id
:= Empty
;
845 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
846 -- Return true if the entity is a procedure with an appropriate
847 -- profile for the Read attribute.
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_Out_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 Read 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
), Name_uRead
);
888 and then Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
891 Error_Msg_Sloc
:= Sloc
(Pnam
);
892 Error_Msg_N
("read attribute already defined #", Nam
);
899 if Is_Entity_Name
(Expr
) then
900 if not Is_Overloaded
(Expr
) then
901 if Has_Good_Profile
(Entity
(Expr
)) then
902 Subp
:= Entity
(Expr
);
906 Get_First_Interp
(Expr
, I
, It
);
908 while Present
(It
.Nam
) loop
909 if Has_Good_Profile
(It
.Nam
) then
914 Get_Next_Interp
(I
, It
);
919 if Present
(Subp
) then
920 Set_Entity
(Expr
, Subp
);
921 Set_Etype
(Expr
, Etype
(Subp
));
922 New_Stream_Procedure
(N
, U_Ent
, Subp
, Name_uRead
, True);
924 Error_Msg_N
("incorrect expression for read attribute", Expr
);
933 -- Size attribute definition clause
935 when Attribute_Size
=> Size
: declare
936 Size
: constant Uint
:= Static_Integer
(Expr
);
943 if Has_Size_Clause
(U_Ent
) then
944 Error_Msg_N
("size already given for &", Nam
);
946 elsif not Is_Type
(U_Ent
)
947 and then Ekind
(U_Ent
) /= E_Variable
948 and then Ekind
(U_Ent
) /= E_Constant
950 Error_Msg_N
("size cannot be given for &", Nam
);
952 elsif Is_Array_Type
(U_Ent
)
953 and then not Is_Constrained
(U_Ent
)
956 ("size cannot be given for unconstrained array", Nam
);
958 elsif Size
/= No_Uint
then
960 if Is_Type
(U_Ent
) then
963 Etyp
:= Etype
(U_Ent
);
966 -- Check size, note that Gigi is in charge of checking
967 -- that the size of an array or record type is OK. Also
968 -- we do not check the size in the ordinary fixed-point
969 -- case, since it is too early to do so (there may be a
970 -- subsequent small clause that affects the size). We can
971 -- check the size if a small clause has already been given.
973 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
974 or else Has_Small_Clause
(U_Ent
)
976 Check_Size
(Expr
, Etyp
, Size
, Biased
);
977 Set_Has_Biased_Representation
(U_Ent
, Biased
);
980 -- For types set RM_Size and Esize if possible
982 if Is_Type
(U_Ent
) then
983 Set_RM_Size
(U_Ent
, Size
);
985 -- For scalar types, increase Object_Size to power of 2,
986 -- but not less than a storage unit in any case (i.e.,
987 -- normally this means it will be byte addressable).
989 if Is_Scalar_Type
(U_Ent
) then
990 if Size
<= System_Storage_Unit
then
991 Init_Esize
(U_Ent
, System_Storage_Unit
);
992 elsif Size
<= 16 then
993 Init_Esize
(U_Ent
, 16);
994 elsif Size
<= 32 then
995 Init_Esize
(U_Ent
, 32);
997 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
1000 -- For all other types, object size = value size. The
1001 -- backend will adjust as needed.
1004 Set_Esize
(U_Ent
, Size
);
1007 Alignment_Check_For_Esize_Change
(U_Ent
);
1009 -- For objects, set Esize only
1012 Set_Esize
(U_Ent
, Size
);
1015 Set_Has_Size_Clause
(U_Ent
);
1023 -- Small attribute definition clause
1025 when Attribute_Small
=> Small
: declare
1026 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
1030 Analyze_And_Resolve
(Expr
, Any_Real
);
1032 if Etype
(Expr
) = Any_Type
then
1035 elsif not Is_Static_Expression
(Expr
) then
1036 Error_Msg_N
("small requires static expression", Expr
);
1040 Small
:= Expr_Value_R
(Expr
);
1042 if Small
<= Ureal_0
then
1043 Error_Msg_N
("small value must be greater than zero", Expr
);
1049 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
1051 ("small requires an ordinary fixed point type", Nam
);
1053 elsif Has_Small_Clause
(U_Ent
) then
1054 Error_Msg_N
("small already given for &", Nam
);
1056 elsif Small
> Delta_Value
(U_Ent
) then
1058 ("small value must not be greater then delta value", Nam
);
1061 Set_Small_Value
(U_Ent
, Small
);
1062 Set_Small_Value
(Implicit_Base
, Small
);
1063 Set_Has_Small_Clause
(U_Ent
);
1064 Set_Has_Small_Clause
(Implicit_Base
);
1065 Set_Has_Non_Standard_Rep
(Implicit_Base
);
1073 -- Storage_Size attribute definition clause
1075 when Attribute_Storage_Size
=> Storage_Size
: declare
1076 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
1080 if Is_Task_Type
(U_Ent
) then
1084 if not Is_Access_Type
(U_Ent
)
1085 and then Ekind
(U_Ent
) /= E_Task_Type
1087 Error_Msg_N
("storage size cannot be given for &", Nam
);
1089 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
1091 ("storage size cannot be given for a derived access type",
1094 elsif Has_Storage_Size_Clause
(Btype
) then
1095 Error_Msg_N
("storage size already given for &", Nam
);
1098 Analyze_And_Resolve
(Expr
, Any_Integer
);
1100 if Is_Access_Type
(U_Ent
) then
1102 if Present
(Associated_Storage_Pool
(U_Ent
)) then
1103 Error_Msg_N
("storage pool already given for &", Nam
);
1107 if Compile_Time_Known_Value
(Expr
)
1108 and then Expr_Value
(Expr
) = 0
1110 Set_No_Pool_Assigned
(Btype
);
1113 else -- Is_Task_Type (U_Ent)
1114 Sprag
:= Get_Rep_Pragma
(Btype
, Name_Storage_Size
);
1116 if Present
(Sprag
) then
1117 Error_Msg_Sloc
:= Sloc
(Sprag
);
1119 ("Storage_Size already specified#", Nam
);
1124 Set_Has_Storage_Size_Clause
(Btype
);
1132 -- Storage_Pool attribute definition clause
1134 when Attribute_Storage_Pool
=> Storage_Pool
: declare
1138 if Ekind
(U_Ent
) /= E_Access_Type
1139 and then Ekind
(U_Ent
) /= E_General_Access_Type
1142 "storage pool can only be given for access types", Nam
);
1145 elsif Is_Derived_Type
(U_Ent
) then
1147 ("storage pool cannot be given for a derived access type",
1150 elsif Has_Storage_Size_Clause
(U_Ent
) then
1151 Error_Msg_N
("storage size already given for &", Nam
);
1154 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
1155 Error_Msg_N
("storage pool already given for &", Nam
);
1160 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
1162 -- If the argument is a name that is not an entity name, then
1163 -- we construct a renaming operation to define an entity of
1164 -- type storage pool.
1166 if not Is_Entity_Name
(Expr
)
1167 and then Is_Object_Reference
(Expr
)
1170 Make_Defining_Identifier
(Loc
,
1171 Chars
=> New_Internal_Name
('P'));
1174 Rnode
: constant Node_Id
:=
1175 Make_Object_Renaming_Declaration
(Loc
,
1176 Defining_Identifier
=> Pool
,
1178 New_Occurrence_Of
(Etype
(Expr
), Loc
),
1182 Insert_Before
(N
, Rnode
);
1184 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1187 elsif Is_Entity_Name
(Expr
) then
1188 Pool
:= Entity
(Expr
);
1190 -- If pool is a renamed object, get original one. This can
1191 -- happen with an explicit renaming, and within instances.
1193 while Present
(Renamed_Object
(Pool
))
1194 and then Is_Entity_Name
(Renamed_Object
(Pool
))
1196 Pool
:= Entity
(Renamed_Object
(Pool
));
1199 if Present
(Renamed_Object
(Pool
))
1200 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
1201 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
1203 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
1206 if Present
(Etype
(Pool
))
1207 and then Etype
(Pool
) /= RTE
(RE_Stack_Bounded_Pool
)
1208 and then Etype
(Pool
) /= RTE
(RE_Unbounded_Reclaim_Pool
)
1210 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1212 Error_Msg_N
("Non sharable GNAT Pool", Expr
);
1215 -- The pool may be specified as the Storage_Pool of some other
1216 -- type. It is rewritten as a class_wide conversion of the
1217 -- corresponding pool entity.
1219 elsif Nkind
(Expr
) = N_Type_Conversion
1220 and then Is_Entity_Name
(Expression
(Expr
))
1221 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
1223 Pool
:= Entity
(Expression
(Expr
));
1225 if Present
(Etype
(Pool
))
1226 and then Etype
(Pool
) /= RTE
(RE_Stack_Bounded_Pool
)
1227 and then Etype
(Pool
) /= RTE
(RE_Unbounded_Reclaim_Pool
)
1229 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1231 Error_Msg_N
("Non sharable GNAT Pool", Expr
);
1235 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
1244 -- Value_Size attribute definition clause
1246 when Attribute_Value_Size
=> Value_Size
: declare
1247 Size
: constant Uint
:= Static_Integer
(Expr
);
1251 if not Is_Type
(U_Ent
) then
1252 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
1255 (Get_Attribute_Definition_Clause
1256 (U_Ent
, Attribute_Value_Size
))
1258 Error_Msg_N
("Value_Size already given for &", Nam
);
1261 if Is_Elementary_Type
(U_Ent
) then
1262 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
1263 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1266 Set_RM_Size
(U_Ent
, Size
);
1274 -- Write attribute definition clause
1275 -- check for class-wide case will be performed later
1277 when Attribute_Write
=> Write
: declare
1278 Subp
: Entity_Id
:= Empty
;
1283 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
1284 -- Return true if the entity is a procedure with an
1285 -- appropriate profile for the write attribute.
1287 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
1289 Ok
: Boolean := False;
1292 if Ekind
(Subp
) = E_Procedure
then
1293 F
:= First_Formal
(Subp
);
1296 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
1298 Designated_Type
(Etype
(F
)) =
1299 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
1303 and then Parameter_Mode
(F
) = E_In_Parameter
1304 and then Base_Type
(Etype
(F
)) = Base_Type
(Ent
)
1305 and then No
(Next_Formal
(F
));
1311 end Has_Good_Profile
;
1313 -- Start of processing for Write attribute definition
1318 if not Is_Type
(U_Ent
) then
1319 Error_Msg_N
("local name must be a subtype", Nam
);
1323 Pnam
:= TSS
(Base_Type
(U_Ent
), Name_uWrite
);
1326 and then Base_Type
(Etype
(Next_Formal
(First_Formal
(Pnam
))))
1329 Error_Msg_Sloc
:= Sloc
(Pnam
);
1330 Error_Msg_N
("write attribute already defined #", Nam
);
1336 if Is_Entity_Name
(Expr
) then
1337 if not Is_Overloaded
(Expr
) then
1338 if Has_Good_Profile
(Entity
(Expr
)) then
1339 Subp
:= Entity
(Expr
);
1343 Get_First_Interp
(Expr
, I
, It
);
1345 while Present
(It
.Nam
) loop
1346 if Has_Good_Profile
(It
.Nam
) then
1351 Get_Next_Interp
(I
, It
);
1356 if Present
(Subp
) then
1357 Set_Entity
(Expr
, Subp
);
1358 Set_Etype
(Expr
, Etype
(Subp
));
1359 New_Stream_Procedure
(N
, U_Ent
, Subp
, Name_uWrite
);
1361 Error_Msg_N
("incorrect expression for write attribute", Expr
);
1366 -- All other attributes cannot be set
1370 ("attribute& cannot be set with definition clause", N
);
1374 -- The test for the type being frozen must be performed after
1375 -- any expression the clause has been analyzed since the expression
1376 -- itself might cause freezing that makes the clause illegal.
1378 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
1381 end Analyze_Attribute_Definition_Clause
;
1383 ----------------------------
1384 -- Analyze_Code_Statement --
1385 ----------------------------
1387 procedure Analyze_Code_Statement
(N
: Node_Id
) is
1388 HSS
: constant Node_Id
:= Parent
(N
);
1389 SBody
: constant Node_Id
:= Parent
(HSS
);
1390 Subp
: constant Entity_Id
:= Current_Scope
;
1397 -- Analyze and check we get right type, note that this implements the
1398 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1399 -- is the only way that Asm_Insn could possibly be visible.
1401 Analyze_And_Resolve
(Expression
(N
));
1403 if Etype
(Expression
(N
)) = Any_Type
then
1405 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
1406 Error_Msg_N
("incorrect type for code statement", N
);
1410 -- Make sure we appear in the handled statement sequence of a
1411 -- subprogram (RM 13.8(3)).
1413 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
1414 or else Nkind
(SBody
) /= N_Subprogram_Body
1417 ("code statement can only appear in body of subprogram", N
);
1421 -- Do remaining checks (RM 13.8(3)) if not already done
1423 if not Is_Machine_Code_Subprogram
(Subp
) then
1424 Set_Is_Machine_Code_Subprogram
(Subp
);
1426 -- No exception handlers allowed
1428 if Present
(Exception_Handlers
(HSS
)) then
1430 ("exception handlers not permitted in machine code subprogram",
1431 First
(Exception_Handlers
(HSS
)));
1434 -- No declarations other than use clauses and pragmas (we allow
1435 -- certain internally generated declarations as well).
1437 Decl
:= First
(Declarations
(SBody
));
1438 while Present
(Decl
) loop
1439 DeclO
:= Original_Node
(Decl
);
1440 if Comes_From_Source
(DeclO
)
1441 and then Nkind
(DeclO
) /= N_Pragma
1442 and then Nkind
(DeclO
) /= N_Use_Package_Clause
1443 and then Nkind
(DeclO
) /= N_Use_Type_Clause
1444 and then Nkind
(DeclO
) /= N_Implicit_Label_Declaration
1447 ("this declaration not allowed in machine code subprogram",
1454 -- No statements other than code statements, pragmas, and labels.
1455 -- Again we allow certain internally generated statements.
1457 Stmt
:= First
(Statements
(HSS
));
1458 while Present
(Stmt
) loop
1459 StmtO
:= Original_Node
(Stmt
);
1460 if Comes_From_Source
(StmtO
)
1461 and then Nkind
(StmtO
) /= N_Pragma
1462 and then Nkind
(StmtO
) /= N_Label
1463 and then Nkind
(StmtO
) /= N_Code_Statement
1466 ("this statement is not allowed in machine code subprogram",
1474 end Analyze_Code_Statement
;
1476 -----------------------------------------------
1477 -- Analyze_Enumeration_Representation_Clause --
1478 -----------------------------------------------
1480 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
1481 Ident
: constant Node_Id
:= Identifier
(N
);
1482 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
1483 Enumtype
: Entity_Id
;
1489 Err
: Boolean := False;
1491 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
1492 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
1497 -- First some basic error checks
1500 Enumtype
:= Entity
(Ident
);
1502 if Enumtype
= Any_Type
1503 or else Rep_Item_Too_Early
(Enumtype
, N
)
1507 Enumtype
:= Underlying_Type
(Enumtype
);
1510 if not Is_Enumeration_Type
(Enumtype
) then
1512 ("enumeration type required, found}",
1513 Ident
, First_Subtype
(Enumtype
));
1517 if Scope
(Enumtype
) /= Current_Scope
then
1518 Error_Msg_N
("type must be declared in this scope", Ident
);
1521 elsif not Is_First_Subtype
(Enumtype
) then
1522 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
1525 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
1526 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
1529 elsif Root_Type
(Enumtype
) = Standard_Character
1530 or else Root_Type
(Enumtype
) = Standard_Wide_Character
1532 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
1535 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
1536 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
1539 -- Now we process the aggregate. Note that we don't use the normal
1540 -- aggregate code for this purpose, because we don't want any of the
1541 -- normal expansion activities, and a number of special semantic
1542 -- rules apply (including the component type being any integer type)
1544 -- Badent signals that we found some incorrect entries processing
1545 -- the list. The final checks for completeness and ordering are
1546 -- skipped in this case.
1548 Elit
:= First_Literal
(Enumtype
);
1550 -- First the positional entries if any
1552 if Present
(Expressions
(Aggr
)) then
1553 Expr
:= First
(Expressions
(Aggr
));
1554 while Present
(Expr
) loop
1556 Error_Msg_N
("too many entries in aggregate", Expr
);
1560 Val
:= Static_Integer
(Expr
);
1562 if Val
= No_Uint
then
1565 elsif Val
< Lo
or else Hi
< Val
then
1566 Error_Msg_N
("value outside permitted range", Expr
);
1570 Set_Enumeration_Rep
(Elit
, Val
);
1571 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
1577 -- Now process the named entries if present
1579 if Present
(Component_Associations
(Aggr
)) then
1580 Assoc
:= First
(Component_Associations
(Aggr
));
1581 while Present
(Assoc
) loop
1582 Choice
:= First
(Choices
(Assoc
));
1584 if Present
(Next
(Choice
)) then
1586 ("multiple choice not allowed here", Next
(Choice
));
1590 if Nkind
(Choice
) = N_Others_Choice
then
1591 Error_Msg_N
("others choice not allowed here", Choice
);
1594 elsif Nkind
(Choice
) = N_Range
then
1595 -- ??? should allow zero/one element range here
1596 Error_Msg_N
("range not allowed here", Choice
);
1600 Analyze_And_Resolve
(Choice
, Enumtype
);
1602 if Is_Entity_Name
(Choice
)
1603 and then Is_Type
(Entity
(Choice
))
1605 Error_Msg_N
("subtype name not allowed here", Choice
);
1607 -- ??? should allow static subtype with zero/one entry
1609 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
1610 if not Is_Static_Expression
(Choice
) then
1612 ("non-static expression used for choice", Choice
);
1616 Elit
:= Expr_Value_E
(Choice
);
1618 if Present
(Enumeration_Rep_Expr
(Elit
)) then
1619 Error_Msg_Sloc
:= Sloc
(Enumeration_Rep_Expr
(Elit
));
1621 ("representation for& previously given#",
1626 Set_Enumeration_Rep_Expr
(Elit
, Choice
);
1628 Expr
:= Expression
(Assoc
);
1629 Val
:= Static_Integer
(Expr
);
1631 if Val
= No_Uint
then
1634 elsif Val
< Lo
or else Hi
< Val
then
1635 Error_Msg_N
("value outside permitted range", Expr
);
1639 Set_Enumeration_Rep
(Elit
, Val
);
1648 -- Aggregate is fully processed. Now we check that a full set of
1649 -- representations was given, and that they are in range and in order.
1650 -- These checks are only done if no other errors occurred.
1656 Elit
:= First_Literal
(Enumtype
);
1657 while Present
(Elit
) loop
1658 if No
(Enumeration_Rep_Expr
(Elit
)) then
1659 Error_Msg_NE
("missing representation for&!", N
, Elit
);
1662 Val
:= Enumeration_Rep
(Elit
);
1664 if Min
= No_Uint
then
1668 if Val
/= No_Uint
then
1669 if Max
/= No_Uint
and then Val
<= Max
then
1671 ("enumeration value for& not ordered!",
1672 Enumeration_Rep_Expr
(Elit
), Elit
);
1678 -- If there is at least one literal whose representation
1679 -- is not equal to the Pos value, then note that this
1680 -- enumeration type has a non-standard representation.
1682 if Val
/= Enumeration_Pos
(Elit
) then
1683 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
1690 -- Now set proper size information
1693 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
1696 if Has_Size_Clause
(Enumtype
) then
1697 if Esize
(Enumtype
) >= Minsize
then
1702 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
1704 if Esize
(Enumtype
) < Minsize
then
1705 Error_Msg_N
("previously given size is too small", N
);
1708 Set_Has_Biased_Representation
(Enumtype
);
1713 Set_RM_Size
(Enumtype
, Minsize
);
1714 Set_Enum_Esize
(Enumtype
);
1717 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
1718 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
1719 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
1723 -- We repeat the too late test in case it froze itself!
1725 if Rep_Item_Too_Late
(Enumtype
, N
) then
1729 end Analyze_Enumeration_Representation_Clause
;
1731 ----------------------------
1732 -- Analyze_Free_Statement --
1733 ----------------------------
1735 procedure Analyze_Free_Statement
(N
: Node_Id
) is
1737 Analyze
(Expression
(N
));
1738 end Analyze_Free_Statement
;
1740 ------------------------------------------
1741 -- Analyze_Record_Representation_Clause --
1742 ------------------------------------------
1744 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
1745 Loc
: constant Source_Ptr
:= Sloc
(N
);
1746 Ident
: constant Node_Id
:= Identifier
(N
);
1747 Rectype
: Entity_Id
;
1753 Hbit
: Uint
:= Uint_0
;
1758 Max_Bit_So_Far
: Uint
;
1759 -- Records the maximum bit position so far. If all field positoins
1760 -- are monotonically increasing, then we can skip the circuit for
1761 -- checking for overlap, since no overlap is possible.
1763 Overlap_Check_Required
: Boolean;
1764 -- Used to keep track of whether or not an overlap check is required
1766 Ccount
: Natural := 0;
1767 -- Number of component clauses in record rep clause
1771 Rectype
:= Entity
(Ident
);
1773 if Rectype
= Any_Type
1774 or else Rep_Item_Too_Early
(Rectype
, N
)
1778 Rectype
:= Underlying_Type
(Rectype
);
1781 -- First some basic error checks
1783 if not Is_Record_Type
(Rectype
) then
1785 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
1788 elsif Is_Unchecked_Union
(Rectype
) then
1790 ("record rep clause not allowed for Unchecked_Union", N
);
1792 elsif Scope
(Rectype
) /= Current_Scope
then
1793 Error_Msg_N
("type must be declared in this scope", N
);
1796 elsif not Is_First_Subtype
(Rectype
) then
1797 Error_Msg_N
("cannot give record rep clause for subtype", N
);
1800 elsif Has_Record_Rep_Clause
(Rectype
) then
1801 Error_Msg_N
("duplicate record rep clause ignored", N
);
1804 elsif Rep_Item_Too_Late
(Rectype
, N
) then
1808 if Present
(Mod_Clause
(N
)) then
1810 Loc
: constant Source_Ptr
:= Sloc
(N
);
1811 M
: constant Node_Id
:= Mod_Clause
(N
);
1812 P
: constant List_Id
:= Pragmas_Before
(M
);
1821 -- In Tree_Output mode, expansion is disabled, but we must
1822 -- convert the Mod clause into an alignment clause anyway, so
1823 -- that the back-end can compute and back-annotate properly the
1824 -- size and alignment of types that may include this record.
1826 if Operating_Mode
= Check_Semantics
1827 and then Tree_Output
1830 Make_Attribute_Definition_Clause
(Loc
,
1831 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
1832 Chars
=> Name_Alignment
,
1833 Expression
=> Relocate_Node
(Expression
(M
)));
1835 Set_From_At_Mod
(AtM_Nod
);
1836 Insert_After
(N
, AtM_Nod
);
1837 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
1838 Set_Mod_Clause
(N
, Empty
);
1841 -- Get the alignment value to perform error checking
1843 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
1849 -- Clear any existing component clauses for the type (this happens
1850 -- with derived types, where we are now overriding the original)
1852 Fent
:= First_Entity
(Rectype
);
1855 while Present
(Comp
) loop
1856 if Ekind
(Comp
) = E_Component
1857 or else Ekind
(Comp
) = E_Discriminant
1859 Set_Component_Clause
(Comp
, Empty
);
1865 -- All done if no component clauses
1867 CC
:= First
(Component_Clauses
(N
));
1873 -- If a tag is present, then create a component clause that places
1874 -- it at the start of the record (otherwise gigi may place it after
1875 -- other fields that have rep clauses).
1877 if Nkind
(Fent
) = N_Defining_Identifier
1878 and then Chars
(Fent
) = Name_uTag
1880 Set_Component_Bit_Offset
(Fent
, Uint_0
);
1881 Set_Normalized_Position
(Fent
, Uint_0
);
1882 Set_Normalized_First_Bit
(Fent
, Uint_0
);
1883 Set_Normalized_Position_Max
(Fent
, Uint_0
);
1884 Init_Esize
(Fent
, System_Address_Size
);
1886 Set_Component_Clause
(Fent
,
1887 Make_Component_Clause
(Loc
,
1889 Make_Identifier
(Loc
,
1890 Chars
=> Name_uTag
),
1893 Make_Integer_Literal
(Loc
,
1897 Make_Integer_Literal
(Loc
,
1901 Make_Integer_Literal
(Loc
,
1902 UI_From_Int
(System_Address_Size
))));
1904 Ccount
:= Ccount
+ 1;
1907 -- A representation like this applies to the base type
1909 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
1910 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
1911 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
1913 Max_Bit_So_Far
:= Uint_Minus_1
;
1914 Overlap_Check_Required
:= False;
1916 -- Process the component clauses
1918 while Present
(CC
) loop
1920 -- If pragma, just analyze it
1922 if Nkind
(CC
) = N_Pragma
then
1925 -- Processing for real component clause
1928 Ccount
:= Ccount
+ 1;
1929 Posit
:= Static_Integer
(Position
(CC
));
1930 Fbit
:= Static_Integer
(First_Bit
(CC
));
1931 Lbit
:= Static_Integer
(Last_Bit
(CC
));
1934 and then Fbit
/= No_Uint
1935 and then Lbit
/= No_Uint
1939 ("position cannot be negative", Position
(CC
));
1943 ("first bit cannot be negative", First_Bit
(CC
));
1945 -- Values look OK, so find the corresponding record component
1946 -- Even though the syntax allows an attribute reference for
1947 -- implementation-defined components, GNAT does not allow the
1948 -- tag to get an explicit position.
1950 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
1952 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
1953 Error_Msg_N
("position of tag cannot be specified", CC
);
1955 Error_Msg_N
("illegal component name", CC
);
1959 Comp
:= First_Entity
(Rectype
);
1960 while Present
(Comp
) loop
1961 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
1967 -- Maybe component of base type that is absent from
1968 -- statically constrained first subtype.
1970 Comp
:= First_Entity
(Base_Type
(Rectype
));
1971 while Present
(Comp
) loop
1972 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
1979 ("component clause is for non-existent field", CC
);
1981 elsif Present
(Component_Clause
(Comp
)) then
1982 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
1984 ("component clause previously given#", CC
);
1987 -- Update Fbit and Lbit to the actual bit number.
1989 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
1990 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
1992 if Fbit
<= Max_Bit_So_Far
then
1993 Overlap_Check_Required
:= True;
1995 Max_Bit_So_Far
:= Lbit
;
1998 if Has_Size_Clause
(Rectype
)
1999 and then Esize
(Rectype
) <= Lbit
2002 ("bit number out of range of specified size",
2005 Set_Component_Clause
(Comp
, CC
);
2006 Set_Component_Bit_Offset
(Comp
, Fbit
);
2007 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
2008 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
2009 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
2011 Set_Normalized_Position_Max
2012 (Fent
, Normalized_Position
(Fent
));
2014 if Is_Tagged_Type
(Rectype
)
2015 and then Fbit
< System_Address_Size
2018 ("component overlaps tag field of&",
2022 -- Test for large object that is not on a byte
2023 -- boundary, defined as a large packed array not
2024 -- represented by a modular type, or an object for
2025 -- which a size of greater than 64 bits is specified.
2027 if Fbit
mod SSU
/= 0 then
2028 if (Is_Packed_Array_Type
(Etype
(Comp
))
2029 and then Is_Array_Type
2030 (Packed_Array_Type
(Etype
(Comp
))))
2031 or else Esize
(Etype
(Comp
)) > 64
2034 ("large component must be on byte boundary",
2039 -- This information is also set in the
2040 -- corresponding component of the base type,
2041 -- found by accessing the Original_Record_Component
2042 -- link if it is present.
2044 Ocomp
:= Original_Record_Component
(Comp
);
2051 (Component_Name
(CC
),
2056 Set_Has_Biased_Representation
(Comp
, Biased
);
2058 if Present
(Ocomp
) then
2059 Set_Component_Clause
(Ocomp
, CC
);
2060 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
2061 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
2062 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
2063 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
2065 Set_Normalized_Position_Max
2066 (Ocomp
, Normalized_Position
(Ocomp
));
2068 Set_Has_Biased_Representation
2069 (Ocomp
, Has_Biased_Representation
(Comp
));
2072 if Esize
(Comp
) < 0 then
2073 Error_Msg_N
("component size is negative", CC
);
2084 -- Now that we have processed all the component clauses, check for
2085 -- overlap. We have to leave this till last, since the components
2086 -- can appear in any arbitrary order in the representation clause.
2088 -- We do not need this check if all specified ranges were monotonic,
2089 -- as recorded by Overlap_Check_Required being False at this stage.
2091 -- This first section checks if there are any overlapping entries
2092 -- at all. It does this by sorting all entries and then seeing if
2093 -- there are any overlaps. If there are none, then that is decisive,
2094 -- but if there are overlaps, they may still be OK (they may result
2095 -- from fields in different variants).
2097 if Overlap_Check_Required
then
2098 Overlap_Check1
: declare
2100 OC_Fbit
: array (0 .. Ccount
) of Uint
;
2101 -- First-bit values for component clauses, the value is the
2102 -- offset of the first bit of the field from start of record.
2103 -- The zero entry is for use in sorting.
2105 OC_Lbit
: array (0 .. Ccount
) of Uint
;
2106 -- Last-bit values for component clauses, the value is the
2107 -- offset of the last bit of the field from start of record.
2108 -- The zero entry is for use in sorting.
2110 OC_Count
: Natural := 0;
2111 -- Count of entries in OC_Fbit and OC_Lbit
2113 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
2114 -- Compare routine for Sort (See GNAT.Heap_Sort_A)
2116 procedure OC_Move
(From
: Natural; To
: Natural);
2117 -- Move routine for Sort (see GNAT.Heap_Sort_A)
2119 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
2121 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
2124 procedure OC_Move
(From
: Natural; To
: Natural) is
2126 OC_Fbit
(To
) := OC_Fbit
(From
);
2127 OC_Lbit
(To
) := OC_Lbit
(From
);
2131 CC
:= First
(Component_Clauses
(N
));
2132 while Present
(CC
) loop
2133 if Nkind
(CC
) /= N_Pragma
then
2134 Posit
:= Static_Integer
(Position
(CC
));
2135 Fbit
:= Static_Integer
(First_Bit
(CC
));
2136 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2139 and then Fbit
/= No_Uint
2140 and then Lbit
/= No_Uint
2142 OC_Count
:= OC_Count
+ 1;
2143 Posit
:= Posit
* SSU
;
2144 OC_Fbit
(OC_Count
) := Fbit
+ Posit
;
2145 OC_Lbit
(OC_Count
) := Lbit
+ Posit
;
2154 OC_Move
'Unrestricted_Access,
2155 OC_Lt
'Unrestricted_Access);
2157 Overlap_Check_Required
:= False;
2158 for J
in 1 .. OC_Count
- 1 loop
2159 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
2160 Overlap_Check_Required
:= True;
2167 -- If Overlap_Check_Required is still True, then we have to do
2168 -- the full scale overlap check, since we have at least two fields
2169 -- that do overlap, and we need to know if that is OK since they
2170 -- are in the same variant, or whether we have a definite problem
2172 if Overlap_Check_Required
then
2173 Overlap_Check2
: declare
2174 C1_Ent
, C2_Ent
: Entity_Id
;
2175 -- Entities of components being checked for overlap
2178 -- Component_List node whose Component_Items are being checked
2181 -- Component declaration for component being checked
2184 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
2186 -- Loop through all components in record. For each component check
2187 -- for overlap with any of the preceding elements on the component
2188 -- list containing the component, and also, if the component is in
2189 -- a variant, check against components outside the case structure.
2190 -- This latter test is repeated recursively up the variant tree.
2192 Main_Component_Loop
: while Present
(C1_Ent
) loop
2193 if Ekind
(C1_Ent
) /= E_Component
2194 and then Ekind
(C1_Ent
) /= E_Discriminant
2196 goto Continue_Main_Component_Loop
;
2199 -- Skip overlap check if entity has no declaration node. This
2200 -- happens with discriminants in constrained derived types.
2201 -- Probably we are missing some checks as a result, but that
2202 -- does not seem terribly serious ???
2204 if No
(Declaration_Node
(C1_Ent
)) then
2205 goto Continue_Main_Component_Loop
;
2208 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
2210 -- Loop through component lists that need checking. Check the
2211 -- current component list and all lists in variants above us.
2213 Component_List_Loop
: loop
2215 -- If derived type definition, go to full declaration
2216 -- If at outer level, check discriminants if there are any
2218 if Nkind
(Clist
) = N_Derived_Type_Definition
then
2219 Clist
:= Parent
(Clist
);
2222 -- Outer level of record definition, check discriminants
2224 if Nkind
(Clist
) = N_Full_Type_Declaration
2225 or else Nkind
(Clist
) = N_Private_Type_Declaration
2227 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
2229 First_Discriminant
(Defining_Identifier
(Clist
));
2231 while Present
(C2_Ent
) loop
2232 exit when C1_Ent
= C2_Ent
;
2233 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2234 Next_Discriminant
(C2_Ent
);
2238 -- Record extension case
2240 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
2243 -- Otherwise check one component list
2246 Citem
:= First
(Component_Items
(Clist
));
2248 while Present
(Citem
) loop
2249 if Nkind
(Citem
) = N_Component_Declaration
then
2250 C2_Ent
:= Defining_Identifier
(Citem
);
2251 exit when C1_Ent
= C2_Ent
;
2252 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2259 -- Check for variants above us (the parent of the Clist can
2260 -- be a variant, in which case its parent is a variant part,
2261 -- and the parent of the variant part is a component list
2262 -- whose components must all be checked against the current
2263 -- component for overlap.
2265 if Nkind
(Parent
(Clist
)) = N_Variant
then
2266 Clist
:= Parent
(Parent
(Parent
(Clist
)));
2268 -- Check for possible discriminant part in record, this is
2269 -- treated essentially as another level in the recursion.
2270 -- For this case we have the parent of the component list
2271 -- is the record definition, and its parent is the full
2272 -- type declaration which contains the discriminant
2275 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
2276 Clist
:= Parent
(Parent
((Clist
)));
2278 -- If neither of these two cases, we are at the top of
2282 exit Component_List_Loop
;
2284 end loop Component_List_Loop
;
2286 <<Continue_Main_Component_Loop
>>
2287 Next_Entity
(C1_Ent
);
2289 end loop Main_Component_Loop
;
2293 -- For records that have component clauses for all components, and
2294 -- whose size is less than or equal to 32, we need to know the size
2295 -- in the front end to activate possible packed array processing
2296 -- where the component type is a record.
2298 -- At this stage Hbit + 1 represents the first unused bit from all
2299 -- the component clauses processed, so if the component clauses are
2300 -- complete, then this is the length of the record.
2302 -- For records longer than System.Storage_Unit, and for those where
2303 -- not all components have component clauses, the back end determines
2304 -- the length (it may for example be appopriate to round up the size
2305 -- to some convenient boundary, based on alignment considerations etc).
2307 if Unknown_RM_Size
(Rectype
)
2308 and then Hbit
+ 1 <= 32
2310 -- Nothing to do if at least one component with no component clause
2312 Comp
:= First_Entity
(Rectype
);
2313 while Present
(Comp
) loop
2314 if Ekind
(Comp
) = E_Component
2315 or else Ekind
(Comp
) = E_Discriminant
2317 if No
(Component_Clause
(Comp
)) then
2325 -- If we fall out of loop, all components have component clauses
2326 -- and so we can set the size to the maximum value.
2328 Set_RM_Size
(Rectype
, Hbit
+ 1);
2331 end Analyze_Record_Representation_Clause
;
2333 -----------------------------
2334 -- Check_Component_Overlap --
2335 -----------------------------
2337 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
2339 if Present
(Component_Clause
(C1_Ent
))
2340 and then Present
(Component_Clause
(C2_Ent
))
2342 -- Exclude odd case where we have two tag fields in the same
2343 -- record, both at location zero. This seems a bit strange,
2344 -- but it seems to happen in some circumstances ???
2346 if Chars
(C1_Ent
) = Name_uTag
2347 and then Chars
(C2_Ent
) = Name_uTag
2352 -- Here we check if the two fields overlap
2355 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
2356 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
2357 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
2358 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
2361 if E2
<= S1
or else E1
<= S2
then
2365 Component_Name
(Component_Clause
(C2_Ent
));
2366 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
2368 Component_Name
(Component_Clause
(C1_Ent
));
2370 ("component& overlaps & #",
2371 Component_Name
(Component_Clause
(C1_Ent
)));
2375 end Check_Component_Overlap
;
2377 -----------------------------------
2378 -- Check_Constant_Address_Clause --
2379 -----------------------------------
2381 procedure Check_Constant_Address_Clause
2385 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
2386 -- Checks that the given node N represents a name whose 'Address
2387 -- is constant (in the same sense as OK_Constant_Address_Clause,
2388 -- i.e. the address value is the same at the point of declaration
2389 -- of U_Ent and at the time of elaboration of the address clause.
2391 procedure Check_Expr_Constants
(Nod
: Node_Id
);
2392 -- Checks that Nod meets the requirements for a constant address
2393 -- clause in the sense of the enclosing procedure.
2395 procedure Check_List_Constants
(Lst
: List_Id
);
2396 -- Check that all elements of list Lst meet the requirements for a
2397 -- constant address clause in the sense of the enclosing procedure.
2399 -------------------------------
2400 -- Check_At_Constant_Address --
2401 -------------------------------
2403 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
2405 if Is_Entity_Name
(Nod
) then
2406 if Present
(Address_Clause
(Entity
((Nod
)))) then
2408 ("invalid address clause for initialized object &!",
2411 ("address for& cannot" &
2412 " depend on another address clause! ('R'M 13.1(22))!",
2415 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
2416 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
2419 ("invalid address clause for initialized object &!",
2421 Error_Msg_Name_1
:= Chars
(Entity
(Nod
));
2422 Error_Msg_Name_2
:= Chars
(U_Ent
);
2424 ("\% must be defined before % ('R'M 13.1(22))!",
2428 elsif Nkind
(Nod
) = N_Selected_Component
then
2430 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
2433 if (Is_Record_Type
(T
)
2434 and then Has_Discriminants
(T
))
2437 and then Is_Record_Type
(Designated_Type
(T
))
2438 and then Has_Discriminants
(Designated_Type
(T
)))
2441 ("invalid address clause for initialized object &!",
2444 ("\address cannot depend on component" &
2445 " of discriminated record ('R'M 13.1(22))!",
2448 Check_At_Constant_Address
(Prefix
(Nod
));
2452 elsif Nkind
(Nod
) = N_Indexed_Component
then
2453 Check_At_Constant_Address
(Prefix
(Nod
));
2454 Check_List_Constants
(Expressions
(Nod
));
2457 Check_Expr_Constants
(Nod
);
2459 end Check_At_Constant_Address
;
2461 --------------------------
2462 -- Check_Expr_Constants --
2463 --------------------------
2465 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
2467 if Nkind
(Nod
) in N_Has_Etype
2468 and then Etype
(Nod
) = Any_Type
2474 when N_Empty | N_Error
=>
2477 when N_Identifier | N_Expanded_Name
=>
2479 Ent
: constant Entity_Id
:= Entity
(Nod
);
2480 Loc_Ent
: constant Source_Ptr
:= Sloc
(Ent
);
2481 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
2484 if Ekind
(Ent
) = E_Named_Integer
2486 Ekind
(Ent
) = E_Named_Real
2493 Ekind
(Ent
) = E_Constant
2495 Ekind
(Ent
) = E_In_Parameter
2497 -- This is the case where we must have Ent defined
2498 -- before U_Ent. Clearly if they are in different
2499 -- units this requirement is met since the unit
2500 -- containing Ent is already processed.
2502 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
2505 -- Otherwise location of Ent must be before the
2506 -- location of U_Ent, that's what prior defined means.
2508 elsif Loc_Ent
< Loc_U_Ent
then
2513 ("invalid address clause for initialized object &!",
2515 Error_Msg_Name_1
:= Chars
(Ent
);
2516 Error_Msg_Name_2
:= Chars
(U_Ent
);
2518 ("\% must be defined before % ('R'M 13.1(22))!",
2522 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2523 Check_Expr_Constants
(Original_Node
(Nod
));
2527 ("invalid address clause for initialized object &!",
2529 Error_Msg_Name_1
:= Chars
(Ent
);
2531 ("\reference to variable% not allowed ('R'M 13.1(22))!",
2536 when N_Integer_Literal |
2539 N_Character_Literal
=>
2543 Check_Expr_Constants
(Low_Bound
(Nod
));
2544 Check_Expr_Constants
(High_Bound
(Nod
));
2546 when N_Explicit_Dereference
=>
2547 Check_Expr_Constants
(Prefix
(Nod
));
2549 when N_Indexed_Component
=>
2550 Check_Expr_Constants
(Prefix
(Nod
));
2551 Check_List_Constants
(Expressions
(Nod
));
2554 Check_Expr_Constants
(Prefix
(Nod
));
2555 Check_Expr_Constants
(Discrete_Range
(Nod
));
2557 when N_Selected_Component
=>
2558 Check_Expr_Constants
(Prefix
(Nod
));
2560 when N_Attribute_Reference
=>
2562 if (Attribute_Name
(Nod
) = Name_Address
2564 Attribute_Name
(Nod
) = Name_Access
2566 Attribute_Name
(Nod
) = Name_Unchecked_Access
2568 Attribute_Name
(Nod
) = Name_Unrestricted_Access
)
2570 Check_At_Constant_Address
(Prefix
(Nod
));
2573 Check_Expr_Constants
(Prefix
(Nod
));
2574 Check_List_Constants
(Expressions
(Nod
));
2578 Check_List_Constants
(Component_Associations
(Nod
));
2579 Check_List_Constants
(Expressions
(Nod
));
2581 when N_Component_Association
=>
2582 Check_Expr_Constants
(Expression
(Nod
));
2584 when N_Extension_Aggregate
=>
2585 Check_Expr_Constants
(Ancestor_Part
(Nod
));
2586 Check_List_Constants
(Component_Associations
(Nod
));
2587 Check_List_Constants
(Expressions
(Nod
));
2592 when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In
=>
2593 Check_Expr_Constants
(Left_Opnd
(Nod
));
2594 Check_Expr_Constants
(Right_Opnd
(Nod
));
2597 Check_Expr_Constants
(Right_Opnd
(Nod
));
2599 when N_Type_Conversion |
2600 N_Qualified_Expression |
2602 Check_Expr_Constants
(Expression
(Nod
));
2604 when N_Unchecked_Type_Conversion
=>
2605 Check_Expr_Constants
(Expression
(Nod
));
2607 -- If this is a rewritten unchecked conversion, subtypes
2608 -- in this node are those created within the instance.
2609 -- To avoid order of elaboration issues, replace them
2610 -- with their base types. Note that address clauses can
2611 -- cause order of elaboration problems because they are
2612 -- elaborated by the back-end at the point of definition,
2613 -- and may mention entities declared in between (as long
2614 -- as everything is static). It is user-friendly to allow
2615 -- unchecked conversions in this context.
2617 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
2618 Set_Etype
(Expression
(Nod
),
2619 Base_Type
(Etype
(Expression
(Nod
))));
2620 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
2623 when N_Function_Call
=>
2624 if not Is_Pure
(Entity
(Name
(Nod
))) then
2626 ("invalid address clause for initialized object &!",
2630 ("\function & is not pure ('R'M 13.1(22))!",
2631 Nod
, Entity
(Name
(Nod
)));
2634 Check_List_Constants
(Parameter_Associations
(Nod
));
2637 when N_Parameter_Association
=>
2638 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
2642 ("invalid address clause for initialized object &!",
2645 ("\must be constant defined before& ('R'M 13.1(22))!",
2648 end Check_Expr_Constants
;
2650 --------------------------
2651 -- Check_List_Constants --
2652 --------------------------
2654 procedure Check_List_Constants
(Lst
: List_Id
) is
2658 if Present
(Lst
) then
2659 Nod1
:= First
(Lst
);
2660 while Present
(Nod1
) loop
2661 Check_Expr_Constants
(Nod1
);
2665 end Check_List_Constants
;
2667 -- Start of processing for Check_Constant_Address_Clause
2670 Check_Expr_Constants
(Expr
);
2671 end Check_Constant_Address_Clause
;
2677 procedure Check_Size
2681 Biased
: out Boolean)
2683 UT
: constant Entity_Id
:= Underlying_Type
(T
);
2689 -- Immediate return if size is same as standard size or if composite
2690 -- item, or generic type, or type with previous errors.
2693 or else UT
= Any_Type
2694 or else Is_Generic_Type
(UT
)
2695 or else Is_Generic_Type
(Root_Type
(UT
))
2696 or else Is_Composite_Type
(UT
)
2697 or else (Known_Esize
(UT
) and then Siz
= Esize
(UT
))
2701 -- For fixed-point types, don't check minimum if type is not frozen,
2702 -- since type is not known till then
2705 elsif Is_Fixed_Point_Type
(UT
)
2706 and then not Is_Frozen
(UT
)
2710 -- Cases for which a minimum check is required
2713 M
:= UI_From_Int
(Minimum_Size
(UT
));
2717 -- Size is less than minimum size, but one possibility remains
2718 -- that we can manage with the new size if we bias the type
2720 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
2723 Error_Msg_Uint_1
:= M
;
2725 ("size for& too small, minimum allowed is ^", N
, T
);
2733 -------------------------
2734 -- Get_Alignment_Value --
2735 -------------------------
2737 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
2738 Align
: constant Uint
:= Static_Integer
(Expr
);
2741 if Align
= No_Uint
then
2744 elsif Align
<= 0 then
2745 Error_Msg_N
("alignment value must be positive", Expr
);
2749 for J
in Int
range 0 .. 64 loop
2751 M
: constant Uint
:= Uint_2
** J
;
2754 exit when M
= Align
;
2758 ("alignment value must be power of 2", Expr
);
2766 end Get_Alignment_Value
;
2772 procedure Initialize
is
2774 Unchecked_Conversions
.Init
;
2777 -------------------------
2778 -- Is_Operational_Item --
2779 -------------------------
2781 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
2783 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
2787 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
2790 return Id
= Attribute_Input
2791 or else Id
= Attribute_Output
2792 or else Id
= Attribute_Read
2793 or else Id
= Attribute_Write
2794 or else Id
= Attribute_External_Tag
;
2797 end Is_Operational_Item
;
2803 function Minimum_Size
2805 Biased
: Boolean := False)
2808 Lo
: Uint
:= No_Uint
;
2809 Hi
: Uint
:= No_Uint
;
2810 LoR
: Ureal
:= No_Ureal
;
2811 HiR
: Ureal
:= No_Ureal
;
2812 LoSet
: Boolean := False;
2813 HiSet
: Boolean := False;
2817 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
2820 -- If bad type, return 0
2822 if T
= Any_Type
then
2825 -- For generic types, just return zero. There cannot be any legitimate
2826 -- need to know such a size, but this routine may be called with a
2827 -- generic type as part of normal processing.
2829 elsif Is_Generic_Type
(R_Typ
)
2830 or else R_Typ
= Any_Type
2836 elsif Is_Access_Type
(T
) then
2837 return System_Address_Size
;
2839 -- Floating-point types
2841 elsif Is_Floating_Point_Type
(T
) then
2842 return UI_To_Int
(Esize
(R_Typ
));
2846 elsif Is_Discrete_Type
(T
) then
2848 -- The following loop is looking for the nearest compile time
2849 -- known bounds following the ancestor subtype chain. The idea
2850 -- is to find the most restrictive known bounds information.
2854 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
2859 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
2860 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
2867 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
2868 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
2874 Ancest
:= Ancestor_Subtype
(Ancest
);
2877 Ancest
:= Base_Type
(T
);
2879 if Is_Generic_Type
(Ancest
) then
2885 -- Fixed-point types. We can't simply use Expr_Value to get the
2886 -- Corresponding_Integer_Value values of the bounds, since these
2887 -- do not get set till the type is frozen, and this routine can
2888 -- be called before the type is frozen. Similarly the test for
2889 -- bounds being static needs to include the case where we have
2890 -- unanalyzed real literals for the same reason.
2892 elsif Is_Fixed_Point_Type
(T
) then
2894 -- The following loop is looking for the nearest compile time
2895 -- known bounds following the ancestor subtype chain. The idea
2896 -- is to find the most restrictive known bounds information.
2900 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
2905 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
2906 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
2908 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
2915 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
2916 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
2918 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
2924 Ancest
:= Ancestor_Subtype
(Ancest
);
2927 Ancest
:= Base_Type
(T
);
2929 if Is_Generic_Type
(Ancest
) then
2935 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
2936 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
2938 -- No other types allowed
2941 raise Program_Error
;
2944 -- Fall through with Hi and Lo set. Deal with biased case.
2946 if (Biased
and then not Is_Fixed_Point_Type
(T
))
2947 or else Has_Biased_Representation
(T
)
2953 -- Signed case. Note that we consider types like range 1 .. -1 to be
2954 -- signed for the purpose of computing the size, since the bounds
2955 -- have to be accomodated in the base type.
2957 if Lo
< 0 or else Hi
< 0 then
2961 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
2962 -- Note that we accommodate the case where the bounds cross. This
2963 -- can happen either because of the way the bounds are declared
2964 -- or because of the algorithm in Freeze_Fixed_Point_Type.
2978 -- If both bounds are positive, make sure that both are represen-
2979 -- table in the case where the bounds are crossed. This can happen
2980 -- either because of the way the bounds are declared, or because of
2981 -- the algorithm in Freeze_Fixed_Point_Type.
2987 -- S = size, (can accommodate 0 .. (2**size - 1))
2990 while Hi
>= Uint_2
** S
loop
2998 -------------------------
2999 -- New_Stream_Function --
3000 -------------------------
3002 procedure New_Stream_Function
3008 Loc
: constant Source_Ptr
:= Sloc
(N
);
3009 Subp_Id
: Entity_Id
;
3010 Subp_Decl
: Node_Id
;
3014 function Build_Spec
return Node_Id
;
3015 -- Used for declaration and renaming declaration, so that this is
3016 -- treated as a renaming_as_body.
3022 function Build_Spec
return Node_Id
is
3024 Subp_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
3027 Make_Function_Specification
(Loc
,
3028 Defining_Unit_Name
=> Subp_Id
,
3029 Parameter_Specifications
=>
3031 Make_Parameter_Specification
(Loc
,
3032 Defining_Identifier
=>
3033 Make_Defining_Identifier
(Loc
, Name_S
),
3035 Make_Access_Definition
(Loc
,
3038 Designated_Type
(Etype
(F
)), Loc
)))),
3041 New_Reference_To
(Etyp
, Loc
));
3044 -- Start of processing for New_Stream_Function
3047 F
:= First_Formal
(Subp
);
3048 Etyp
:= Etype
(Subp
);
3050 if not Is_Tagged_Type
(Ent
) then
3052 Make_Subprogram_Declaration
(Loc
,
3053 Specification
=> Build_Spec
);
3054 Insert_Action
(N
, Subp_Decl
);
3058 Make_Subprogram_Renaming_Declaration
(Loc
,
3059 Specification
=> Build_Spec
,
3060 Name
=> New_Reference_To
(Subp
, Loc
));
3062 if Is_Tagged_Type
(Ent
) and then not Is_Limited_Type
(Ent
) then
3063 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3065 Insert_Action
(N
, Subp_Decl
);
3066 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3069 end New_Stream_Function
;
3071 --------------------------
3072 -- New_Stream_Procedure --
3073 --------------------------
3075 procedure New_Stream_Procedure
3080 Out_P
: Boolean := False)
3082 Loc
: constant Source_Ptr
:= Sloc
(N
);
3083 Subp_Id
: Entity_Id
;
3084 Subp_Decl
: Node_Id
;
3088 function Build_Spec
return Node_Id
;
3089 -- Used for declaration and renaming declaration, so that this is
3090 -- treated as a renaming_as_body.
3092 function Build_Spec
return Node_Id
is
3094 Subp_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
3097 Make_Procedure_Specification
(Loc
,
3098 Defining_Unit_Name
=> Subp_Id
,
3099 Parameter_Specifications
=>
3101 Make_Parameter_Specification
(Loc
,
3102 Defining_Identifier
=>
3103 Make_Defining_Identifier
(Loc
, Name_S
),
3105 Make_Access_Definition
(Loc
,
3108 Designated_Type
(Etype
(F
)), Loc
))),
3110 Make_Parameter_Specification
(Loc
,
3111 Defining_Identifier
=>
3112 Make_Defining_Identifier
(Loc
, Name_V
),
3113 Out_Present
=> Out_P
,
3115 New_Reference_To
(Etyp
, Loc
))));
3118 -- Start of processing for New_Stream_Function
3121 F
:= First_Formal
(Subp
);
3122 Etyp
:= Etype
(Next_Formal
(F
));
3124 if not Is_Tagged_Type
(Ent
) then
3126 Make_Subprogram_Declaration
(Loc
,
3127 Specification
=> Build_Spec
);
3128 Insert_Action
(N
, Subp_Decl
);
3132 Make_Subprogram_Renaming_Declaration
(Loc
,
3133 Specification
=> Build_Spec
,
3134 Name
=> New_Reference_To
(Subp
, Loc
));
3136 if Is_Tagged_Type
(Ent
) and then not Is_Limited_Type
(Ent
) then
3137 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3139 Insert_Action
(N
, Subp_Decl
);
3140 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3143 end New_Stream_Procedure
;
3145 ---------------------
3146 -- Record_Rep_Item --
3147 ---------------------
3149 procedure Record_Rep_Item
(T
: Entity_Id
; N
: Node_Id
) is
3151 Set_Next_Rep_Item
(N
, First_Rep_Item
(T
));
3152 Set_First_Rep_Item
(T
, N
);
3153 end Record_Rep_Item
;
3155 ------------------------
3156 -- Rep_Item_Too_Early --
3157 ------------------------
3159 function Rep_Item_Too_Early
3165 -- Cannot apply rep items that are not operational items
3168 if Is_Operational_Item
(N
) then
3172 and then Is_Generic_Type
(Root_Type
(T
))
3175 ("representation item not allowed for generic type", N
);
3179 -- Otherwise check for incompleted type
3181 if Is_Incomplete_Or_Private_Type
(T
)
3182 and then No
(Underlying_Type
(T
))
3185 ("representation item must be after full type declaration", N
);
3188 -- If the type has incompleted components, a representation clause is
3189 -- illegal but stream attributes and Convention pragmas are correct.
3191 elsif Has_Private_Component
(T
) then
3192 if Nkind
(N
) = N_Pragma
then
3196 ("representation item must appear after type is fully defined",
3203 end Rep_Item_Too_Early
;
3205 -----------------------
3206 -- Rep_Item_Too_Late --
3207 -----------------------
3209 function Rep_Item_Too_Late
3212 FOnly
: Boolean := False)
3216 Parent_Type
: Entity_Id
;
3219 -- Output the too late message
3221 procedure Too_Late
is
3223 Error_Msg_N
("representation item appears too late!", N
);
3226 -- Start of processing for Rep_Item_Too_Late
3229 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3230 -- types, which may be frozen if they appear in a representation clause
3231 -- for a local type.
3234 and then not From_With_Type
(T
)
3237 S
:= First_Subtype
(T
);
3239 if Present
(Freeze_Node
(S
)) then
3241 ("?no more representation items for }!", Freeze_Node
(S
), S
);
3246 -- Check for case of non-tagged derived type whose parent either has
3247 -- primitive operations, or is a by reference type (RM 13.1(10)).
3251 and then Is_Derived_Type
(T
)
3252 and then not Is_Tagged_Type
(T
)
3254 Parent_Type
:= Etype
(Base_Type
(T
));
3256 if Has_Primitive_Operations
(Parent_Type
) then
3259 ("primitive operations already defined for&!", N
, Parent_Type
);
3262 elsif Is_By_Reference_Type
(Parent_Type
) then
3265 ("parent type & is a by reference type!", N
, Parent_Type
);
3270 -- No error, link item into head of chain of rep items for the entity
3272 Record_Rep_Item
(T
, N
);
3274 end Rep_Item_Too_Late
;
3276 -------------------------
3277 -- Same_Representation --
3278 -------------------------
3280 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
3281 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
3282 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
3285 -- A quick check, if base types are the same, then we definitely have
3286 -- the same representation, because the subtype specific representation
3287 -- attributes (Size and Alignment) do not affect representation from
3288 -- the point of view of this test.
3290 if Base_Type
(T1
) = Base_Type
(T2
) then
3293 elsif Is_Private_Type
(Base_Type
(T2
))
3294 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
3299 -- Tagged types never have differing representations
3301 if Is_Tagged_Type
(T1
) then
3305 -- Representations are definitely different if conventions differ
3307 if Convention
(T1
) /= Convention
(T2
) then
3311 -- Representations are different if component alignments differ
3313 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
3315 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
3316 and then Component_Alignment
(T1
) /= Component_Alignment
(T2
)
3321 -- For arrays, the only real issue is component size. If we know the
3322 -- component size for both arrays, and it is the same, then that's
3323 -- good enough to know we don't have a change of representation.
3325 if Is_Array_Type
(T1
) then
3326 if Known_Component_Size
(T1
)
3327 and then Known_Component_Size
(T2
)
3328 and then Component_Size
(T1
) = Component_Size
(T2
)
3334 -- Types definitely have same representation if neither has non-standard
3335 -- representation since default representations are always consistent.
3336 -- If only one has non-standard representation, and the other does not,
3337 -- then we consider that they do not have the same representation. They
3338 -- might, but there is no way of telling early enough.
3340 if Has_Non_Standard_Rep
(T1
) then
3341 if not Has_Non_Standard_Rep
(T2
) then
3345 return not Has_Non_Standard_Rep
(T2
);
3348 -- Here the two types both have non-standard representation, and we
3349 -- need to determine if they have the same non-standard representation
3351 -- For arrays, we simply need to test if the component sizes are the
3352 -- same. Pragma Pack is reflected in modified component sizes, so this
3353 -- check also deals with pragma Pack.
3355 if Is_Array_Type
(T1
) then
3356 return Component_Size
(T1
) = Component_Size
(T2
);
3358 -- Tagged types always have the same representation, because it is not
3359 -- possible to specify different representations for common fields.
3361 elsif Is_Tagged_Type
(T1
) then
3364 -- Case of record types
3366 elsif Is_Record_Type
(T1
) then
3368 -- Packed status must conform
3370 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
3373 -- Otherwise we must check components. Typ2 maybe a constrained
3374 -- subtype with fewer components, so we compare the components
3375 -- of the base types.
3378 Record_Case
: declare
3379 CD1
, CD2
: Entity_Id
;
3381 function Same_Rep
return Boolean;
3382 -- CD1 and CD2 are either components or discriminants. This
3383 -- function tests whether the two have the same representation
3385 function Same_Rep
return Boolean is
3387 if No
(Component_Clause
(CD1
)) then
3388 return No
(Component_Clause
(CD2
));
3392 Present
(Component_Clause
(CD2
))
3394 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
3396 Esize
(CD1
) = Esize
(CD2
);
3400 -- Start processing for Record_Case
3403 if Has_Discriminants
(T1
) then
3404 CD1
:= First_Discriminant
(T1
);
3405 CD2
:= First_Discriminant
(T2
);
3407 while Present
(CD1
) loop
3408 if not Same_Rep
then
3411 Next_Discriminant
(CD1
);
3412 Next_Discriminant
(CD2
);
3417 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
3418 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
3420 while Present
(CD1
) loop
3421 if not Same_Rep
then
3424 Next_Component
(CD1
);
3425 Next_Component
(CD2
);
3433 -- For enumeration types, we must check each literal to see if the
3434 -- representation is the same. Note that we do not permit enumeration
3435 -- representation clauses for Character and Wide_Character, so these
3436 -- cases were already dealt with.
3438 elsif Is_Enumeration_Type
(T1
) then
3440 Enumeration_Case
: declare
3444 L1
:= First_Literal
(T1
);
3445 L2
:= First_Literal
(T2
);
3447 while Present
(L1
) loop
3448 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
3458 end Enumeration_Case
;
3460 -- Any other types have the same representation for these purposes
3466 end Same_Representation
;
3468 --------------------
3469 -- Set_Enum_Esize --
3470 --------------------
3472 procedure Set_Enum_Esize
(T
: Entity_Id
) is
3480 -- Find the minimum standard size (8,16,32,64) that fits
3482 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
3483 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
3486 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
3487 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3489 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
3492 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
3495 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
3500 if Hi
< Uint_2
**08 then
3501 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
3503 elsif Hi
< Uint_2
**16 then
3506 elsif Hi
< Uint_2
**32 then
3509 else pragma Assert
(Hi
< Uint_2
**63);
3514 -- That minimum is the proper size unless we have a foreign convention
3515 -- and the size required is 32 or less, in which case we bump the size
3516 -- up to 32. This is required for C and C++ and seems reasonable for
3517 -- all other foreign conventions.
3519 if Has_Foreign_Convention
(T
)
3520 and then Esize
(T
) < Standard_Integer_Size
3522 Init_Esize
(T
, Standard_Integer_Size
);
3530 -----------------------------------
3531 -- Validate_Unchecked_Conversion --
3532 -----------------------------------
3534 procedure Validate_Unchecked_Conversion
3536 Act_Unit
: Entity_Id
)
3543 -- Obtain source and target types. Note that we call Ancestor_Subtype
3544 -- here because the processing for generic instantiation always makes
3545 -- subtypes, and we want the original frozen actual types.
3547 -- If we are dealing with private types, then do the check on their
3548 -- fully declared counterparts if the full declarations have been
3549 -- encountered (they don't have to be visible, but they must exist!)
3551 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
3553 if Is_Private_Type
(Source
)
3554 and then Present
(Underlying_Type
(Source
))
3556 Source
:= Underlying_Type
(Source
);
3559 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
3561 -- If either type is generic, the instantiation happens within a
3562 -- generic unit, and there is nothing to check. The proper check
3563 -- will happen when the enclosing generic is instantiated.
3565 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
3569 if Is_Private_Type
(Target
)
3570 and then Present
(Underlying_Type
(Target
))
3572 Target
:= Underlying_Type
(Target
);
3575 -- Source may be unconstrained array, but not target
3577 if Is_Array_Type
(Target
)
3578 and then not Is_Constrained
(Target
)
3581 ("unchecked conversion to unconstrained array not allowed", N
);
3585 -- Make entry in unchecked conversion table for later processing
3586 -- by Validate_Unchecked_Conversions, which will check sizes and
3587 -- alignments (using values set by the back-end where possible).
3589 Unchecked_Conversions
.Append
3590 (New_Val
=> UC_Entry
'
3595 -- Generate N_Validate_Unchecked_Conversion node for back end if
3596 -- the back end needs to perform special validation checks. At the
3597 -- current time, only the JVM version requires such checks.
3601 Make_Validate_Unchecked_Conversion (Sloc (N));
3602 Set_Source_Type (Vnode, Source);
3603 Set_Target_Type (Vnode, Target);
3604 Insert_After (N, Vnode);
3606 end Validate_Unchecked_Conversion;
3608 ------------------------------------
3609 -- Validate_Unchecked_Conversions --
3610 ------------------------------------
3612 procedure Validate_Unchecked_Conversions is
3614 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
3616 T : UC_Entry renames Unchecked_Conversions.Table (N);
3618 Enode : constant Node_Id := T.Enode;
3619 Source : constant Entity_Id := T.Source;
3620 Target : constant Entity_Id := T.Target;
3626 -- This validation check, which warns if we have unequal sizes
3627 -- for unchecked conversion, and thus potentially implementation
3628 -- dependent semantics, is one of the few occasions on which we
3629 -- use the official RM size instead of Esize. See description
3630 -- in Einfo "Handling of Type'Size Values" for details.
3632 if Serious_Errors_Detected = 0
3633 and then Known_Static_RM_Size (Source)
3634 and then Known_Static_RM_Size (Target)
3636 Source_Siz := RM_Size (Source);
3637 Target_Siz := RM_Size (Target);
3639 if Source_Siz /= Target_Siz then
3640 Warn_On_Instance := True;
3642 ("types for unchecked conversion have different sizes?",
3645 if All_Errors_Mode then
3646 Error_Msg_Name_1 := Chars (Source);
3647 Error_Msg_Uint_1 := Source_Siz;
3648 Error_Msg_Name_2 := Chars (Target);
3649 Error_Msg_Uint_2 := Target_Siz;
3651 ("\size of % is ^, size of % is ^?", Enode);
3653 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
3655 if Is_Discrete_Type (Source)
3656 and then Is_Discrete_Type (Target)
3658 if Source_Siz > Target_Siz then
3660 ("\^ high order bits of source will be ignored?",
3663 elsif Is_Modular_Integer_Type (Source) then
3665 ("\source will be extended with ^ high order " &
3666 "zero bits?", Enode);
3670 ("\source will be extended with ^ high order " &
3675 elsif Source_Siz < Target_Siz then
3676 if Is_Discrete_Type (Target) then
3677 if Bytes_Big_Endian then
3679 ("\target value will include ^ undefined " &
3684 ("\target value will include ^ undefined " &
3691 ("\^ trailing bits of target value will be " &
3692 "undefined?", Enode);
3695 else pragma Assert (Source_Siz > Target_Siz);
3697 ("\^ trailing bits of source will be ignored?",
3702 Warn_On_Instance := False;
3706 -- If both types are access types, we need to check the alignment.
3707 -- If the alignment of both is specified, we can do it here.
3709 if Serious_Errors_Detected = 0
3710 and then Ekind (Source) in Access_Kind
3711 and then Ekind (Target) in Access_Kind
3712 and then Target_Strict_Alignment
3713 and then Present (Designated_Type (Source))
3714 and then Present (Designated_Type (Target))
3717 D_Source : constant Entity_Id := Designated_Type (Source);
3718 D_Target : constant Entity_Id := Designated_Type (Target);
3721 if Known_Alignment (D_Source)
3722 and then Known_Alignment (D_Target)
3725 Source_Align : constant Uint := Alignment (D_Source);
3726 Target_Align : constant Uint := Alignment (D_Target);
3729 if Source_Align < Target_Align
3730 and then not Is_Tagged_Type (D_Source)
3732 Warn_On_Instance := True;
3733 Error_Msg_Uint_1 := Target_Align;
3734 Error_Msg_Uint_2 := Source_Align;
3735 Error_Msg_Node_2 := D_Source;
3737 ("alignment of & (^) is stricter than " &
3738 "alignment of & (^)?", Enode, D_Target);
3740 if All_Errors_Mode then
3742 ("\resulting access value may have invalid " &
3743 "alignment?", Enode);
3746 Warn_On_Instance := False;
3754 end Validate_Unchecked_Conversions;
3760 procedure Warn_Overlay
3765 Old : Entity_Id := Empty;
3769 if not Address_Clause_Overlay_Warnings then
3774 and then (Has_Non_Null_Base_Init_Proc (Typ)
3775 or else Is_Access_Type (Typ))
3776 and then not Is_Imported (Entity (Nam))
3778 if Nkind (Expr) = N_Attribute_Reference
3779 and then Is_Entity_Name (Prefix (Expr))
3781 Old := Entity (Prefix (Expr));
3783 elsif Is_Entity_Name (Expr)
3784 and then Ekind (Entity (Expr)) = E_Constant
3786 Decl := Declaration_Node (Entity (Expr));
3788 if Nkind (Decl) = N_Object_Declaration
3789 and then Present (Expression (Decl))
3790 and then Nkind (Expression (Decl)) = N_Attribute_Reference
3791 and then Is_Entity_Name (Prefix (Expression (Decl)))
3793 Old := Entity (Prefix (Expression (Decl)));
3795 elsif Nkind (Expr) = N_Function_Call then
3799 -- A function call (most likely to To_Address) is probably not
3800 -- an overlay, so skip warning. Ditto if the function call was
3801 -- inlined and transformed into an entity.
3803 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
3807 Decl := Next (Parent (Expr));
3809 -- If a pragma Import follows, we assume that it is for the current
3810 -- target of the address clause, and skip the warning.
3813 and then Nkind (Decl) = N_Pragma
3814 and then Chars (Decl) = Name_Import
3819 if Present (Old) then
3820 Error_Msg_Node_2 := Old;
3822 ("default initialization of & may modify &?",
3826 ("default initialization of & may modify overlaid storage?",
3830 -- Add friendly warning if initialization comes from a packed array
3833 if Is_Record_Type (Typ) then
3838 Comp := First_Component (Typ);
3840 while Present (Comp) loop
3841 if Nkind (Parent (Comp)) = N_Component_Declaration
3842 and then Present (Expression (Parent (Comp)))
3845 elsif Is_Array_Type (Etype (Comp))
3846 and then Present (Packed_Array_Type (Etype (Comp)))
3849 ("packed array component& will be initialized to zero?",
3853 Next_Component (Comp);
3860 ("use pragma Import for & to " &
3861 "suppress initialization ('R
'M B
.1(24))?
",