1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Einfo
; use Einfo
;
28 with Namet
; use Namet
;
29 with Nlists
; use Nlists
;
30 with Nmake
; use Nmake
;
32 with Rtsfind
; use Rtsfind
;
33 with Sem_Util
; use Sem_Util
;
34 with Sinfo
; use Sinfo
;
35 with Snames
; use Snames
;
36 with Stand
; use Stand
;
37 with Tbuild
; use Tbuild
;
38 with Ttypes
; use Ttypes
;
39 with Uintp
; use Uintp
;
41 package body Exp_Strm
is
43 -----------------------
44 -- Local Subprograms --
45 -----------------------
47 procedure Build_Array_Read_Write_Procedure
53 -- Common routine shared to build either an array Read procedure or an
54 -- array Write procedure, Nam is Name_Read or Name_Write to select which.
55 -- Pnam is the defining identifier for the constructed procedure. The
56 -- other parameters are as for Build_Array_Read_Procedure except that
57 -- the first parameter Nod supplies the Sloc to be used to generate code.
59 procedure Build_Record_Read_Write_Procedure
65 -- Common routine shared to build a record Read Write procedure, Nam
66 -- is Name_Read or Name_Write to select which. Pnam is the defining
67 -- identifier for the constructed procedure. The other parameters are
68 -- as for Build_Record_Read_Procedure.
70 procedure Build_Stream_Function
77 -- Called to build an array or record stream function. The first three
78 -- arguments are the same as Build_Record_Or_Elementary_Input_Function.
79 -- Decls and Stms are the declarations and statements for the body and
80 -- The parameter Fnam is the name of the constructed function.
82 function Has_Stream_Standard_Rep
(U_Type
: Entity_Id
) return Boolean;
83 -- This function is used to test the type U_Type, to determine if it has
84 -- a standard representation from a streaming point of view. Standard means
85 -- that it has a standard representation (e.g. no enumeration rep clause),
86 -- and the size of the root type is the same as the streaming size (which
87 -- is defined as value specified by a Stream_Size clause if present, or
88 -- the Esize of U_Type if not).
90 function Make_Stream_Subprogram_Name
93 Nam
: TSS_Name_Type
) return Entity_Id
;
94 -- Return the entity that identifies the stream subprogram for type Typ
95 -- that is identified by the given Nam. This procedure deals with the
96 -- difference between tagged types (where a single subprogram associated
97 -- with the type is generated) and all other cases (where a subprogram
98 -- is generated at the point of the stream attribute reference). The
99 -- Loc parameter is used as the Sloc of the created entity.
101 function Stream_Base_Type
(E
: Entity_Id
) return Entity_Id
;
102 -- Stream attributes work on the basis of the base type except for the
103 -- array case. For the array case, we do not go to the base type, but
104 -- to the first subtype if it is constrained. This avoids problems with
105 -- incorrect conversions in the packed array case. Stream_Base_Type is
106 -- exactly this function (returns the base type, unless we have an array
107 -- type whose first subtype is constrained, in which case it returns the
110 --------------------------------
111 -- Build_Array_Input_Function --
112 --------------------------------
114 -- The function we build looks like
116 -- function typSI[_nnn] (S : access RST) return Typ is
117 -- L1 : constant Index_Type_1 := Index_Type_1'Input (S);
118 -- H1 : constant Index_Type_1 := Index_Type_1'Input (S);
119 -- L2 : constant Index_Type_2 := Index_Type_2'Input (S);
120 -- H2 : constant Index_Type_2 := Index_Type_2'Input (S);
122 -- Ln : constant Index_Type_n := Index_Type_n'Input (S);
123 -- Hn : constant Index_Type_n := Index_Type_n'Input (S);
125 -- V : Typ'Base (L1 .. H1, L2 .. H2, ... Ln .. Hn)
132 -- Note: the suffix [_nnn] is present for non-tagged types, where we
133 -- generate a local subprogram at the point of the occurrence of the
134 -- attribute reference, so the name must be unique.
136 procedure Build_Array_Input_Function
140 Fnam
: out Entity_Id
)
142 Dim
: constant Pos
:= Number_Dimensions
(Typ
);
153 Indx
:= First_Index
(Typ
);
155 for J
in 1 .. Dim
loop
156 Lnam
:= New_External_Name
('L', J
);
157 Hnam
:= New_External_Name
('H', J
);
160 Make_Object_Declaration
(Loc
,
161 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Lnam
),
162 Constant_Present
=> True,
163 Object_Definition
=> New_Occurrence_Of
(Etype
(Indx
), Loc
),
165 Make_Attribute_Reference
(Loc
,
167 New_Occurrence_Of
(Stream_Base_Type
(Etype
(Indx
)), Loc
),
168 Attribute_Name
=> Name_Input
,
169 Expressions
=> New_List
(Make_Identifier
(Loc
, Name_S
)))));
172 Make_Object_Declaration
(Loc
,
173 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Hnam
),
174 Constant_Present
=> True,
176 New_Occurrence_Of
(Stream_Base_Type
(Etype
(Indx
)), Loc
),
178 Make_Attribute_Reference
(Loc
,
180 New_Occurrence_Of
(Stream_Base_Type
(Etype
(Indx
)), Loc
),
181 Attribute_Name
=> Name_Input
,
182 Expressions
=> New_List
(Make_Identifier
(Loc
, Name_S
)))));
186 Low_Bound
=> Make_Identifier
(Loc
, Lnam
),
187 High_Bound
=> Make_Identifier
(Loc
, Hnam
)));
192 -- If the first subtype is constrained, use it directly. Otherwise
193 -- build a subtype indication with the proper bounds.
195 if Is_Constrained
(Stream_Base_Type
(Typ
)) then
197 Make_Object_Declaration
(Loc
,
198 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
200 New_Occurrence_Of
(Stream_Base_Type
(Typ
), Loc
)));
203 Make_Object_Declaration
(Loc
,
204 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
206 Make_Subtype_Indication
(Loc
,
208 New_Occurrence_Of
(Stream_Base_Type
(Typ
), Loc
),
210 Make_Index_Or_Discriminant_Constraint
(Loc
,
211 Constraints
=> Ranges
))));
215 Make_Attribute_Reference
(Loc
,
216 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
217 Attribute_Name
=> Name_Read
,
218 Expressions
=> New_List
(
219 Make_Identifier
(Loc
, Name_S
),
220 Make_Identifier
(Loc
, Name_V
))),
222 Make_Simple_Return_Statement
(Loc
,
223 Expression
=> Make_Identifier
(Loc
, Name_V
)));
226 Make_Defining_Identifier
(Loc
,
227 Chars
=> Make_TSS_Name_Local
(Typ
, TSS_Stream_Input
));
229 Build_Stream_Function
(Loc
, Typ
, Decl
, Fnam
, Decls
, Stms
);
230 end Build_Array_Input_Function
;
232 ----------------------------------
233 -- Build_Array_Output_Procedure --
234 ----------------------------------
236 procedure Build_Array_Output_Procedure
240 Pnam
: out Entity_Id
)
246 -- Build series of statements to output bounds
248 Indx
:= First_Index
(Typ
);
251 for J
in 1 .. Number_Dimensions
(Typ
) loop
253 Make_Attribute_Reference
(Loc
,
255 New_Occurrence_Of
(Stream_Base_Type
(Etype
(Indx
)), Loc
),
256 Attribute_Name
=> Name_Write
,
257 Expressions
=> New_List
(
258 Make_Identifier
(Loc
, Name_S
),
259 Make_Attribute_Reference
(Loc
,
260 Prefix
=> Make_Identifier
(Loc
, Name_V
),
261 Attribute_Name
=> Name_First
,
262 Expressions
=> New_List
(
263 Make_Integer_Literal
(Loc
, J
))))));
266 Make_Attribute_Reference
(Loc
,
268 New_Occurrence_Of
(Stream_Base_Type
(Etype
(Indx
)), Loc
),
269 Attribute_Name
=> Name_Write
,
270 Expressions
=> New_List
(
271 Make_Identifier
(Loc
, Name_S
),
272 Make_Attribute_Reference
(Loc
,
273 Prefix
=> Make_Identifier
(Loc
, Name_V
),
274 Attribute_Name
=> Name_Last
,
275 Expressions
=> New_List
(
276 Make_Integer_Literal
(Loc
, J
))))));
281 -- Append Write attribute to write array elements
284 Make_Attribute_Reference
(Loc
,
285 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
286 Attribute_Name
=> Name_Write
,
287 Expressions
=> New_List
(
288 Make_Identifier
(Loc
, Name_S
),
289 Make_Identifier
(Loc
, Name_V
))));
292 Make_Defining_Identifier
(Loc
,
293 Chars
=> Make_TSS_Name_Local
(Typ
, TSS_Stream_Output
));
295 Build_Stream_Procedure
(Loc
, Typ
, Decl
, Pnam
, Stms
, False);
296 end Build_Array_Output_Procedure
;
298 --------------------------------
299 -- Build_Array_Read_Procedure --
300 --------------------------------
302 procedure Build_Array_Read_Procedure
306 Pnam
: out Entity_Id
)
308 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
312 Make_Defining_Identifier
(Loc
,
313 Chars
=> Make_TSS_Name_Local
(Typ
, TSS_Stream_Read
));
314 Build_Array_Read_Write_Procedure
(Nod
, Typ
, Decl
, Pnam
, Name_Read
);
315 end Build_Array_Read_Procedure
;
317 --------------------------------------
318 -- Build_Array_Read_Write_Procedure --
319 --------------------------------------
321 -- The form of the array read/write procedure is as follows:
323 -- procedure pnam (S : access RST, V : [out] Typ) is
325 -- for L1 in V'Range (1) loop
326 -- for L2 in V'Range (2) loop
328 -- for Ln in V'Range (n) loop
329 -- Component_Type'Read/Write (S, V (L1, L2, .. Ln));
336 -- The out keyword for V is supplied in the Read case
338 procedure Build_Array_Read_Write_Procedure
345 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
346 Ndim
: constant Pos
:= Number_Dimensions
(Typ
);
347 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
354 -- First build the inner attribute call
358 for J
in 1 .. Ndim
loop
359 Append_To
(Exl
, Make_Identifier
(Loc
, New_External_Name
('L', J
)));
363 Make_Attribute_Reference
(Loc
,
364 Prefix
=> New_Occurrence_Of
(Stream_Base_Type
(Ctyp
), Loc
),
365 Attribute_Name
=> Nam
,
366 Expressions
=> New_List
(
367 Make_Identifier
(Loc
, Name_S
),
368 Make_Indexed_Component
(Loc
,
369 Prefix
=> Make_Identifier
(Loc
, Name_V
),
370 Expressions
=> Exl
)));
372 -- The corresponding stream attribute for the component type of the
373 -- array may be user-defined, and be frozen after the type for which
374 -- we are generating the stream subprogram. In that case, freeze the
375 -- stream attribute of the component type, whose declaration could not
376 -- generate any additional freezing actions in any case.
378 if Nam
= Name_Read
then
379 RW
:= TSS
(Base_Type
(Ctyp
), TSS_Stream_Read
);
381 RW
:= TSS
(Base_Type
(Ctyp
), TSS_Stream_Write
);
385 and then not Is_Frozen
(RW
)
390 -- Now this is the big loop to wrap that statement up in a sequence
391 -- of loops. The first time around, Stm is the attribute call. The
392 -- second and subsequent times, Stm is an inner loop.
394 for J
in 1 .. Ndim
loop
396 Make_Implicit_Loop_Statement
(Nod
,
398 Make_Iteration_Scheme
(Loc
,
399 Loop_Parameter_Specification
=>
400 Make_Loop_Parameter_Specification
(Loc
,
401 Defining_Identifier
=>
402 Make_Defining_Identifier
(Loc
,
403 Chars
=> New_External_Name
('L', Ndim
- J
+ 1)),
405 Discrete_Subtype_Definition
=>
406 Make_Attribute_Reference
(Loc
,
407 Prefix
=> Make_Identifier
(Loc
, Name_V
),
408 Attribute_Name
=> Name_Range
,
410 Expressions
=> New_List
(
411 Make_Integer_Literal
(Loc
, Ndim
- J
+ 1))))),
413 Statements
=> New_List
(Stm
));
417 Build_Stream_Procedure
418 (Loc
, Typ
, Decl
, Pnam
, New_List
(Stm
), Nam
= Name_Read
);
419 end Build_Array_Read_Write_Procedure
;
421 ---------------------------------
422 -- Build_Array_Write_Procedure --
423 ---------------------------------
425 procedure Build_Array_Write_Procedure
429 Pnam
: out Entity_Id
)
431 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
435 Make_Defining_Identifier
(Loc
,
436 Chars
=> Make_TSS_Name_Local
(Typ
, TSS_Stream_Write
));
437 Build_Array_Read_Write_Procedure
(Nod
, Typ
, Decl
, Pnam
, Name_Write
);
438 end Build_Array_Write_Procedure
;
440 ---------------------------------
441 -- Build_Elementary_Input_Call --
442 ---------------------------------
444 function Build_Elementary_Input_Call
(N
: Node_Id
) return Node_Id
is
445 Loc
: constant Source_Ptr
:= Sloc
(N
);
446 P_Type
: constant Entity_Id
:= Entity
(Prefix
(N
));
447 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
448 Rt_Type
: constant Entity_Id
:= Root_Type
(U_Type
);
449 FST
: constant Entity_Id
:= First_Subtype
(U_Type
);
450 Strm
: constant Node_Id
:= First
(Expressions
(N
));
451 Targ
: constant Node_Id
:= Next
(Strm
);
457 -- Compute the size of the stream element. This is either the size of
458 -- the first subtype or if given the size of the Stream_Size attribute.
460 if Has_Stream_Size_Clause
(FST
) then
461 P_Size
:= Static_Integer
(Expression
(Stream_Size_Clause
(FST
)));
463 P_Size
:= Esize
(FST
);
466 -- Check first for Boolean and Character. These are enumeration types,
467 -- but we treat them specially, since they may require special handling
468 -- in the transfer protocol. However, this special handling only applies
469 -- if they have standard representation, otherwise they are treated like
470 -- any other enumeration type.
472 if Rt_Type
= Standard_Boolean
473 and then Has_Stream_Standard_Rep
(U_Type
)
477 elsif Rt_Type
= Standard_Character
478 and then Has_Stream_Standard_Rep
(U_Type
)
482 elsif Rt_Type
= Standard_Wide_Character
483 and then Has_Stream_Standard_Rep
(U_Type
)
487 elsif Rt_Type
= Standard_Wide_Wide_Character
488 and then Has_Stream_Standard_Rep
(U_Type
)
492 -- Floating point types
494 elsif Is_Floating_Point_Type
(U_Type
) then
496 -- Question: should we use P_Size or Rt_Type to distinguish between
497 -- possible floating point types? If a non-standard size or a stream
498 -- size is specified, then we should certainly use the size. But if
499 -- we have two types the same (notably Short_Float_Size = Float_Size
500 -- which is close to universally true, and Long_Long_Float_Size =
501 -- Long_Float_Size, true on most targets except the x86), then we
502 -- would really rather use the root type, so that if people want to
503 -- fiddle with System.Stream_Attributes to get inter-target portable
504 -- streams, they get the size they expect. Consider in particular the
505 -- case of a stream written on an x86, with 96-bit Long_Long_Float
506 -- being read into a non-x86 target with 64 bit Long_Long_Float. A
507 -- special version of System.Stream_Attributes can deal with this
508 -- provided the proper type is always used.
510 -- To deal with these two requirements we add the special checks
511 -- on equal sizes and use the root type to distinguish.
513 if P_Size
<= Standard_Short_Float_Size
514 and then (Standard_Short_Float_Size
/= Standard_Float_Size
515 or else Rt_Type
= Standard_Short_Float
)
519 elsif P_Size
<= Standard_Float_Size
then
522 elsif P_Size
<= Standard_Long_Float_Size
523 and then (Standard_Long_Float_Size
/= Standard_Long_Long_Float_Size
524 or else Rt_Type
= Standard_Float
)
532 -- Signed integer types. Also includes signed fixed-point types and
533 -- enumeration types with a signed representation.
535 -- Note on signed integer types. We do not consider types as signed for
536 -- this purpose if they have no negative numbers, or if they have biased
537 -- representation. The reason is that the value in either case basically
538 -- represents an unsigned value.
540 -- For example, consider:
542 -- type W is range 0 .. 2**32 - 1;
543 -- for W'Size use 32;
545 -- This is a signed type, but the representation is unsigned, and may
546 -- be outside the range of a 32-bit signed integer, so this must be
547 -- treated as 32-bit unsigned.
549 -- Similarly, if we have
551 -- type W is range -1 .. +254;
554 -- then the representation is unsigned
556 elsif not Is_Unsigned_Type
(FST
)
558 (Is_Fixed_Point_Type
(U_Type
)
560 Is_Enumeration_Type
(U_Type
)
562 (Is_Signed_Integer_Type
(U_Type
)
563 and then not Has_Biased_Representation
(FST
)))
565 if P_Size
<= Standard_Short_Short_Integer_Size
then
568 elsif P_Size
<= Standard_Short_Integer_Size
then
571 elsif P_Size
<= Standard_Integer_Size
then
574 elsif P_Size
<= Standard_Long_Integer_Size
then
581 -- Unsigned integer types, also includes unsigned fixed-point types
582 -- and enumeration types with an unsigned representation (note that
583 -- we know they are unsigned because we already tested for signed).
585 -- Also includes signed integer types that are unsigned in the sense
586 -- that they do not include negative numbers. See above for details.
588 elsif Is_Modular_Integer_Type
(U_Type
)
589 or else Is_Fixed_Point_Type
(U_Type
)
590 or else Is_Enumeration_Type
(U_Type
)
591 or else Is_Signed_Integer_Type
(U_Type
)
593 if P_Size
<= Standard_Short_Short_Integer_Size
then
596 elsif P_Size
<= Standard_Short_Integer_Size
then
599 elsif P_Size
<= Standard_Integer_Size
then
602 elsif P_Size
<= Standard_Long_Integer_Size
then
609 else pragma Assert
(Is_Access_Type
(U_Type
));
610 if P_Size
> System_Address_Size
then
617 -- Call the function, and do an unchecked conversion of the result
618 -- to the actual type of the prefix. If the target is a discriminant,
619 -- and we are in the body of the default implementation of a 'Read
620 -- attribute, set target type to force a constraint check (13.13.2(35)).
621 -- If the type of the discriminant is currently private, add another
622 -- unchecked conversion from the full view.
624 if Nkind
(Targ
) = N_Identifier
625 and then Is_Internal_Name
(Chars
(Targ
))
626 and then Is_TSS
(Scope
(Entity
(Targ
)), TSS_Stream_Read
)
629 Unchecked_Convert_To
(Base_Type
(U_Type
),
630 Make_Function_Call
(Loc
,
631 Name
=> New_Occurrence_Of
(RTE
(Lib_RE
), Loc
),
632 Parameter_Associations
=> New_List
(
633 Relocate_Node
(Strm
))));
635 Set_Do_Range_Check
(Res
);
636 if Base_Type
(P_Type
) /= Base_Type
(U_Type
) then
637 Res
:= Unchecked_Convert_To
(Base_Type
(P_Type
), Res
);
644 Unchecked_Convert_To
(P_Type
,
645 Make_Function_Call
(Loc
,
646 Name
=> New_Occurrence_Of
(RTE
(Lib_RE
), Loc
),
647 Parameter_Associations
=> New_List
(
648 Relocate_Node
(Strm
))));
650 end Build_Elementary_Input_Call
;
652 ---------------------------------
653 -- Build_Elementary_Write_Call --
654 ---------------------------------
656 function Build_Elementary_Write_Call
(N
: Node_Id
) return Node_Id
is
657 Loc
: constant Source_Ptr
:= Sloc
(N
);
658 P_Type
: constant Entity_Id
:= Entity
(Prefix
(N
));
659 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
660 Rt_Type
: constant Entity_Id
:= Root_Type
(U_Type
);
661 FST
: constant Entity_Id
:= First_Subtype
(U_Type
);
662 Strm
: constant Node_Id
:= First
(Expressions
(N
));
663 Item
: constant Node_Id
:= Next
(Strm
);
669 -- Compute the size of the stream element. This is either the size of
670 -- the first subtype or if given the size of the Stream_Size attribute.
672 if Has_Stream_Size_Clause
(FST
) then
673 P_Size
:= Static_Integer
(Expression
(Stream_Size_Clause
(FST
)));
675 P_Size
:= Esize
(FST
);
678 -- Find the routine to be called
680 -- Check for First Boolean and Character. These are enumeration types,
681 -- but we treat them specially, since they may require special handling
682 -- in the transfer protocol. However, this special handling only applies
683 -- if they have standard representation, otherwise they are treated like
684 -- any other enumeration type.
686 if Rt_Type
= Standard_Boolean
687 and then Has_Stream_Standard_Rep
(U_Type
)
691 elsif Rt_Type
= Standard_Character
692 and then Has_Stream_Standard_Rep
(U_Type
)
696 elsif Rt_Type
= Standard_Wide_Character
697 and then Has_Stream_Standard_Rep
(U_Type
)
701 elsif Rt_Type
= Standard_Wide_Wide_Character
702 and then Has_Stream_Standard_Rep
(U_Type
)
706 -- Floating point types
708 elsif Is_Floating_Point_Type
(U_Type
) then
710 -- Question: should we use P_Size or Rt_Type to distinguish between
711 -- possible floating point types? If a non-standard size or a stream
712 -- size is specified, then we should certainly use the size. But if
713 -- we have two types the same (notably Short_Float_Size = Float_Size
714 -- which is close to universally true, and Long_Long_Float_Size =
715 -- Long_Float_Size, true on most targets except the x86), then we
716 -- would really rather use the root type, so that if people want to
717 -- fiddle with System.Stream_Attributes to get inter-target portable
718 -- streams, they get the size they expect. Consider in particular the
719 -- case of a stream written on an x86, with 96-bit Long_Long_Float
720 -- being read into a non-x86 target with 64 bit Long_Long_Float. A
721 -- special version of System.Stream_Attributes can deal with this
722 -- provided the proper type is always used.
724 -- To deal with these two requirements we add the special checks
725 -- on equal sizes and use the root type to distinguish.
727 if P_Size
<= Standard_Short_Float_Size
728 and then (Standard_Short_Float_Size
/= Standard_Float_Size
729 or else Rt_Type
= Standard_Short_Float
)
733 elsif P_Size
<= Standard_Float_Size
then
736 elsif P_Size
<= Standard_Long_Float_Size
737 and then (Standard_Long_Float_Size
/= Standard_Long_Long_Float_Size
738 or else Rt_Type
= Standard_Float
)
746 -- Signed integer types. Also includes signed fixed-point types and
747 -- signed enumeration types share this circuitry.
749 -- Note on signed integer types. We do not consider types as signed for
750 -- this purpose if they have no negative numbers, or if they have biased
751 -- representation. The reason is that the value in either case basically
752 -- represents an unsigned value.
754 -- For example, consider:
756 -- type W is range 0 .. 2**32 - 1;
757 -- for W'Size use 32;
759 -- This is a signed type, but the representation is unsigned, and may
760 -- be outside the range of a 32-bit signed integer, so this must be
761 -- treated as 32-bit unsigned.
763 -- Similarly, the representation is also unsigned if we have:
765 -- type W is range -1 .. +254;
768 -- forcing a biased and unsigned representation
770 elsif not Is_Unsigned_Type
(FST
)
772 (Is_Fixed_Point_Type
(U_Type
)
774 Is_Enumeration_Type
(U_Type
)
776 (Is_Signed_Integer_Type
(U_Type
)
777 and then not Has_Biased_Representation
(FST
)))
779 if P_Size
<= Standard_Short_Short_Integer_Size
then
781 elsif P_Size
<= Standard_Short_Integer_Size
then
783 elsif P_Size
<= Standard_Integer_Size
then
785 elsif P_Size
<= Standard_Long_Integer_Size
then
791 -- Unsigned integer types, also includes unsigned fixed-point types
792 -- and unsigned enumeration types (note we know they are unsigned
793 -- because we already tested for signed above).
795 -- Also includes signed integer types that are unsigned in the sense
796 -- that they do not include negative numbers. See above for details.
798 elsif Is_Modular_Integer_Type
(U_Type
)
799 or else Is_Fixed_Point_Type
(U_Type
)
800 or else Is_Enumeration_Type
(U_Type
)
801 or else Is_Signed_Integer_Type
(U_Type
)
803 if P_Size
<= Standard_Short_Short_Integer_Size
then
805 elsif P_Size
<= Standard_Short_Integer_Size
then
807 elsif P_Size
<= Standard_Integer_Size
then
809 elsif P_Size
<= Standard_Long_Integer_Size
then
815 else pragma Assert
(Is_Access_Type
(U_Type
));
817 if P_Size
> System_Address_Size
then
824 -- Unchecked-convert parameter to the required type (i.e. the type of
825 -- the corresponding parameter, and call the appropriate routine.
827 Libent
:= RTE
(Lib_RE
);
830 Make_Procedure_Call_Statement
(Loc
,
831 Name
=> New_Occurrence_Of
(Libent
, Loc
),
832 Parameter_Associations
=> New_List
(
833 Relocate_Node
(Strm
),
834 Unchecked_Convert_To
(Etype
(Next_Formal
(First_Formal
(Libent
))),
835 Relocate_Node
(Item
))));
836 end Build_Elementary_Write_Call
;
838 -----------------------------------------
839 -- Build_Mutable_Record_Read_Procedure --
840 -----------------------------------------
842 procedure Build_Mutable_Record_Read_Procedure
846 Pnam
: out Entity_Id
)
848 Out_Formal
: Node_Id
;
849 -- Expression denoting the out formal parameter
851 Dcls
: constant List_Id
:= New_List
;
852 -- Declarations for the 'Read body
854 Stms
: List_Id
:= New_List
;
855 -- Statements for the 'Read body
858 -- Entity of the discriminant being processed
860 Tmp_For_Disc
: Entity_Id
;
861 -- Temporary object used to read the value of Disc
863 Tmps_For_Discs
: constant List_Id
:= New_List
;
864 -- List of object declarations for temporaries holding the read values
865 -- for the discriminants.
867 Cstr
: constant List_Id
:= New_List
;
868 -- List of constraints to be applied on temporary record
870 Discriminant_Checks
: constant List_Id
:= New_List
;
871 -- List of discriminant checks to be performed if the actual object
874 Tmp
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_V
);
875 -- Temporary record must hide formal (assignments to components of the
876 -- record are always generated with V as the identifier for the record).
878 Constrained_Stms
: List_Id
:= New_List
;
879 -- Statements within the block where we have the constrained temporary
883 Disc
:= First_Discriminant
(Typ
);
885 -- A mutable type cannot be a tagged type, so we generate a new name
886 -- for the stream procedure.
889 Make_Defining_Identifier
(Loc
,
890 Chars
=> Make_TSS_Name_Local
(Typ
, TSS_Stream_Read
));
893 Make_Selected_Component
(Loc
,
894 Prefix
=> New_Occurrence_Of
(Pnam
, Loc
),
895 Selector_Name
=> Make_Identifier
(Loc
, Name_V
));
897 -- Generate Reads for the discriminants of the type. The discriminants
898 -- need to be read before the rest of the components, so that
899 -- variants are initialized correctly. The discriminants must be read
900 -- into temporary variables so an incomplete Read (interrupted by an
901 -- exception, for example) does not alter the passed object.
903 while Present
(Disc
) loop
904 Tmp_For_Disc
:= Make_Defining_Identifier
(Loc
,
905 New_External_Name
(Chars
(Disc
), "D"));
907 Append_To
(Tmps_For_Discs
,
908 Make_Object_Declaration
(Loc
,
909 Defining_Identifier
=> Tmp_For_Disc
,
910 Object_Definition
=> New_Occurrence_Of
(Etype
(Disc
), Loc
)));
911 Set_No_Initialization
(Last
(Tmps_For_Discs
));
914 Make_Attribute_Reference
(Loc
,
915 Prefix
=> New_Occurrence_Of
(Etype
(Disc
), Loc
),
916 Attribute_Name
=> Name_Read
,
917 Expressions
=> New_List
(
918 Make_Identifier
(Loc
, Name_S
),
919 New_Occurrence_Of
(Tmp_For_Disc
, Loc
))));
922 Make_Discriminant_Association
(Loc
,
923 Selector_Names
=> New_List
(New_Occurrence_Of
(Disc
, Loc
)),
924 Expression
=> New_Occurrence_Of
(Tmp_For_Disc
, Loc
)));
926 Append_To
(Discriminant_Checks
,
927 Make_Raise_Constraint_Error
(Loc
,
930 Left_Opnd
=> New_Occurrence_Of
(Tmp_For_Disc
, Loc
),
932 Make_Selected_Component
(Loc
,
933 Prefix
=> New_Copy_Tree
(Out_Formal
),
934 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))),
935 Reason
=> CE_Discriminant_Check_Failed
));
936 Next_Discriminant
(Disc
);
939 -- Generate reads for the components of the record (including
940 -- those that depend on discriminants).
942 Build_Record_Read_Write_Procedure
(Loc
, Typ
, Decl
, Pnam
, Name_Read
);
944 -- If Typ has controlled components (i.e. if it is classwide
945 -- or Has_Controlled), or components constrained using the discriminants
946 -- of Typ, then we need to ensure that all component assignments
947 -- are performed on an object that has been appropriately constrained
948 -- prior to being initialized. To this effect, we wrap the component
949 -- assignments in a block where V is a constrained temporary.
952 Make_Object_Declaration
(Loc
,
953 Defining_Identifier
=> Tmp
,
955 Make_Subtype_Indication
(Loc
,
956 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
958 Make_Index_Or_Discriminant_Constraint
(Loc
,
959 Constraints
=> Cstr
))));
961 Constrained_Stms
:= Statements
(Handled_Statement_Sequence
(Decl
));
963 Make_Block_Statement
(Loc
,
964 Declarations
=> Dcls
,
965 Handled_Statement_Sequence
=> Parent
(Constrained_Stms
)));
967 Append_To
(Constrained_Stms
,
968 Make_Implicit_If_Statement
(Pnam
,
970 Make_Attribute_Reference
(Loc
,
971 Prefix
=> New_Copy_Tree
(Out_Formal
),
972 Attribute_Name
=> Name_Constrained
),
973 Then_Statements
=> Discriminant_Checks
));
975 Append_To
(Constrained_Stms
,
976 Make_Assignment_Statement
(Loc
,
978 Expression
=> Make_Identifier
(Loc
, Name_V
)));
980 if Is_Unchecked_Union
(Typ
) then
982 -- If this is an unchecked union, the stream procedure is erroneous,
983 -- because there are no discriminants to read.
985 -- This should generate a warning ???
989 Make_Raise_Program_Error
(Loc
,
990 Reason
=> PE_Unchecked_Union_Restriction
));
993 Set_Declarations
(Decl
, Tmps_For_Discs
);
994 Set_Handled_Statement_Sequence
(Decl
,
995 Make_Handled_Sequence_Of_Statements
(Loc
,
996 Statements
=> Stms
));
997 end Build_Mutable_Record_Read_Procedure
;
999 ------------------------------------------
1000 -- Build_Mutable_Record_Write_Procedure --
1001 ------------------------------------------
1003 procedure Build_Mutable_Record_Write_Procedure
1007 Pnam
: out Entity_Id
)
1015 Disc
:= First_Discriminant
(Typ
);
1017 -- Generate Writes for the discriminants of the type
1018 -- If the type is an unchecked union, use the default values of
1019 -- the discriminants, because they are not stored.
1021 while Present
(Disc
) loop
1022 if Is_Unchecked_Union
(Typ
) then
1024 New_Copy_Tree
(Discriminant_Default_Value
(Disc
));
1027 Make_Selected_Component
(Loc
,
1028 Prefix
=> Make_Identifier
(Loc
, Name_V
),
1029 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
));
1033 Make_Attribute_Reference
(Loc
,
1034 Prefix
=> New_Occurrence_Of
(Etype
(Disc
), Loc
),
1035 Attribute_Name
=> Name_Write
,
1036 Expressions
=> New_List
(
1037 Make_Identifier
(Loc
, Name_S
),
1040 Next_Discriminant
(Disc
);
1043 -- A mutable type cannot be a tagged type, so we generate a new name
1044 -- for the stream procedure.
1047 Make_Defining_Identifier
(Loc
,
1048 Chars
=> Make_TSS_Name_Local
(Typ
, TSS_Stream_Write
));
1049 Build_Record_Read_Write_Procedure
(Loc
, Typ
, Decl
, Pnam
, Name_Write
);
1051 -- Write the discriminants before the rest of the components, so
1052 -- that discriminant values are properly set of variants, etc.
1054 if Is_Non_Empty_List
(
1055 Statements
(Handled_Statement_Sequence
(Decl
)))
1058 (First
(Statements
(Handled_Statement_Sequence
(Decl
))), Stms
);
1060 Set_Statements
(Handled_Statement_Sequence
(Decl
), Stms
);
1062 end Build_Mutable_Record_Write_Procedure
;
1064 -----------------------------------------------
1065 -- Build_Record_Or_Elementary_Input_Function --
1066 -----------------------------------------------
1068 -- The function we build looks like
1070 -- function InputN (S : access RST) return Typ is
1071 -- C1 : constant Disc_Type_1;
1072 -- Discr_Type_1'Read (S, C1);
1073 -- C2 : constant Disc_Type_2;
1074 -- Discr_Type_2'Read (S, C2);
1076 -- Cn : constant Disc_Type_n;
1077 -- Discr_Type_n'Read (S, Cn);
1078 -- V : Typ (C1, C2, .. Cn)
1085 -- The discriminants are of course only present in the case of a record
1086 -- with discriminants. In the case of a record with no discriminants, or
1087 -- an elementary type, then no Cn constants are defined.
1089 procedure Build_Record_Or_Elementary_Input_Function
1093 Fnam
: out Entity_Id
)
1110 if Has_Discriminants
(Typ
) then
1111 Discr
:= First_Discriminant
(Typ
);
1113 while Present
(Discr
) loop
1114 Cn
:= New_External_Name
('C', J
);
1117 Make_Object_Declaration
(Loc
,
1118 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Cn
),
1119 Object_Definition
=>
1120 New_Occurrence_Of
(Etype
(Discr
), Loc
)));
1123 Make_Attribute_Reference
(Loc
,
1124 Prefix
=> New_Occurrence_Of
(Etype
(Discr
), Loc
),
1125 Attribute_Name
=> Name_Read
,
1126 Expressions
=> New_List
(
1127 Make_Identifier
(Loc
, Name_S
),
1128 Make_Identifier
(Loc
, Cn
))));
1130 Append_To
(Constr
, Make_Identifier
(Loc
, Cn
));
1132 Next_Discriminant
(Discr
);
1137 Make_Subtype_Indication
(Loc
,
1138 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
1140 Make_Index_Or_Discriminant_Constraint
(Loc
,
1141 Constraints
=> Constr
));
1143 -- If no discriminants, then just use the type with no constraint
1146 Odef
:= New_Occurrence_Of
(Typ
, Loc
);
1149 -- For Ada 2005 we create an extended return statement encapsulating
1150 -- the result object and 'Read call, which is needed in general for
1151 -- proper handling of build-in-place results (such as when the result
1152 -- type is inherently limited).
1154 -- Perhaps we should just generate an extended return in all cases???
1157 Make_Object_Declaration
(Loc
,
1158 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
1159 Object_Definition
=> Odef
);
1161 -- If the type is an access type, do not perform default initialization.
1162 -- The object is about to get its value from Read, and if the type is
1163 -- null excluding we do not want spurious warnings on an initial null.
1165 if Is_Access_Type
(Typ
) then
1166 Set_No_Initialization
(Obj_Decl
);
1169 if Ada_Version
>= Ada_05
then
1171 Make_Extended_Return_Statement
(Loc
,
1172 Return_Object_Declarations
=> New_List
(Obj_Decl
),
1173 Handled_Statement_Sequence
=>
1174 Make_Handled_Sequence_Of_Statements
(Loc
,
1175 New_List
(Make_Attribute_Reference
(Loc
,
1176 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
1177 Attribute_Name
=> Name_Read
,
1178 Expressions
=> New_List
(
1179 Make_Identifier
(Loc
, Name_S
),
1180 Make_Identifier
(Loc
, Name_V
)))))));
1183 Append_To
(Decls
, Obj_Decl
);
1186 Make_Attribute_Reference
(Loc
,
1187 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
1188 Attribute_Name
=> Name_Read
,
1189 Expressions
=> New_List
(
1190 Make_Identifier
(Loc
, Name_S
),
1191 Make_Identifier
(Loc
, Name_V
))),
1193 Make_Simple_Return_Statement
(Loc
,
1194 Expression
=> Make_Identifier
(Loc
, Name_V
)));
1197 Fnam
:= Make_Stream_Subprogram_Name
(Loc
, Typ
, TSS_Stream_Input
);
1199 Build_Stream_Function
(Loc
, Typ
, Decl
, Fnam
, Decls
, Stms
);
1200 end Build_Record_Or_Elementary_Input_Function
;
1202 -------------------------------------------------
1203 -- Build_Record_Or_Elementary_Output_Procedure --
1204 -------------------------------------------------
1206 procedure Build_Record_Or_Elementary_Output_Procedure
1210 Pnam
: out Entity_Id
)
1219 -- Note that of course there will be no discriminants for the
1220 -- elementary type case, so Has_Discriminants will be False.
1222 if Has_Discriminants
(Typ
) then
1223 Disc
:= First_Discriminant
(Typ
);
1225 while Present
(Disc
) loop
1227 -- If the type is an unchecked union, it must have default
1228 -- discriminants (this is checked earlier), and those defaults
1229 -- are written out to the stream.
1231 if Is_Unchecked_Union
(Typ
) then
1232 Disc_Ref
:= New_Copy_Tree
(Discriminant_Default_Value
(Disc
));
1236 Make_Selected_Component
(Loc
,
1237 Prefix
=> Make_Identifier
(Loc
, Name_V
),
1238 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
));
1242 Make_Attribute_Reference
(Loc
,
1244 New_Occurrence_Of
(Stream_Base_Type
(Etype
(Disc
)), Loc
),
1245 Attribute_Name
=> Name_Write
,
1246 Expressions
=> New_List
(
1247 Make_Identifier
(Loc
, Name_S
),
1250 Next_Discriminant
(Disc
);
1255 Make_Attribute_Reference
(Loc
,
1256 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
1257 Attribute_Name
=> Name_Write
,
1258 Expressions
=> New_List
(
1259 Make_Identifier
(Loc
, Name_S
),
1260 Make_Identifier
(Loc
, Name_V
))));
1262 Pnam
:= Make_Stream_Subprogram_Name
(Loc
, Typ
, TSS_Stream_Output
);
1264 Build_Stream_Procedure
(Loc
, Typ
, Decl
, Pnam
, Stms
, False);
1265 end Build_Record_Or_Elementary_Output_Procedure
;
1267 ---------------------------------
1268 -- Build_Record_Read_Procedure --
1269 ---------------------------------
1271 procedure Build_Record_Read_Procedure
1275 Pnam
: out Entity_Id
)
1278 Pnam
:= Make_Stream_Subprogram_Name
(Loc
, Typ
, TSS_Stream_Read
);
1279 Build_Record_Read_Write_Procedure
(Loc
, Typ
, Decl
, Pnam
, Name_Read
);
1280 end Build_Record_Read_Procedure
;
1282 ---------------------------------------
1283 -- Build_Record_Read_Write_Procedure --
1284 ---------------------------------------
1286 -- The form of the record read/write procedure is as shown by the
1287 -- following example for a case with one discriminant case variant:
1289 -- procedure pnam (S : access RST, V : [out] Typ) is
1291 -- Component_Type'Read/Write (S, V.component);
1292 -- Component_Type'Read/Write (S, V.component);
1294 -- Component_Type'Read/Write (S, V.component);
1296 -- case V.discriminant is
1298 -- Component_Type'Read/Write (S, V.component);
1299 -- Component_Type'Read/Write (S, V.component);
1301 -- Component_Type'Read/Write (S, V.component);
1304 -- Component_Type'Read/Write (S, V.component);
1305 -- Component_Type'Read/Write (S, V.component);
1307 -- Component_Type'Read/Write (S, V.component);
1312 -- The out keyword for V is supplied in the Read case
1314 procedure Build_Record_Read_Write_Procedure
1325 In_Limited_Extension
: Boolean := False;
1326 -- Set to True while processing the record extension definition
1327 -- for an extension of a limited type (for which an ancestor type
1328 -- has an explicit Nam attribute definition).
1330 function Make_Component_List_Attributes
(CL
: Node_Id
) return List_Id
;
1331 -- Returns a sequence of attributes to process the components that
1332 -- are referenced in the given component list.
1334 function Make_Field_Attribute
(C
: Entity_Id
) return Node_Id
;
1335 -- Given C, the entity for a discriminant or component, build
1336 -- an attribute for the corresponding field values.
1338 function Make_Field_Attributes
(Clist
: List_Id
) return List_Id
;
1339 -- Given Clist, a component items list, construct series of attributes
1340 -- for fieldwise processing of the corresponding components.
1342 ------------------------------------
1343 -- Make_Component_List_Attributes --
1344 ------------------------------------
1346 function Make_Component_List_Attributes
(CL
: Node_Id
) return List_Id
is
1347 CI
: constant List_Id
:= Component_Items
(CL
);
1348 VP
: constant Node_Id
:= Variant_Part
(CL
);
1358 Result
:= Make_Field_Attributes
(CI
);
1360 if Present
(VP
) then
1363 V
:= First_Non_Pragma
(Variants
(VP
));
1364 while Present
(V
) loop
1367 DC
:= First
(Discrete_Choices
(V
));
1368 while Present
(DC
) loop
1369 Append_To
(DCH
, New_Copy_Tree
(DC
));
1374 Make_Case_Statement_Alternative
(Loc
,
1375 Discrete_Choices
=> DCH
,
1377 Make_Component_List_Attributes
(Component_List
(V
))));
1378 Next_Non_Pragma
(V
);
1381 -- Note: in the following, we make sure that we use new occurrence
1382 -- of for the selector, since there are cases in which we make a
1383 -- reference to a hidden discriminant that is not visible.
1385 -- If the enclosing record is an unchecked_union, we use the
1386 -- default expressions for the discriminant (it must exist)
1387 -- because we cannot generate a reference to it, given that
1388 -- it is not stored..
1390 if Is_Unchecked_Union
(Scope
(Entity
(Name
(VP
)))) then
1393 (Discriminant_Default_Value
(Entity
(Name
(VP
))));
1396 Make_Selected_Component
(Loc
,
1397 Prefix
=> Make_Identifier
(Loc
, Name_V
),
1399 New_Occurrence_Of
(Entity
(Name
(VP
)), Loc
));
1403 Make_Case_Statement
(Loc
,
1404 Expression
=> D_Ref
,
1405 Alternatives
=> Alts
));
1409 end Make_Component_List_Attributes
;
1411 --------------------------
1412 -- Make_Field_Attribute --
1413 --------------------------
1415 function Make_Field_Attribute
(C
: Entity_Id
) return Node_Id
is
1416 Field_Typ
: constant Entity_Id
:= Stream_Base_Type
(Etype
(C
));
1418 TSS_Names
: constant array (Name_Input
.. Name_Write
) of
1420 (Name_Read
=> TSS_Stream_Read
,
1421 Name_Write
=> TSS_Stream_Write
,
1422 Name_Input
=> TSS_Stream_Input
,
1423 Name_Output
=> TSS_Stream_Output
,
1424 others => TSS_Null
);
1425 pragma Assert
(TSS_Names
(Nam
) /= TSS_Null
);
1428 if In_Limited_Extension
1429 and then Is_Limited_Type
(Field_Typ
)
1430 and then No
(Find_Inherited_TSS
(Field_Typ
, TSS_Names
(Nam
)))
1432 -- The declaration is illegal per 13.13.2(9/1), and this is
1433 -- enforced in Exp_Ch3.Check_Stream_Attributes. Keep the caller
1434 -- happy by returning a null statement.
1436 return Make_Null_Statement
(Loc
);
1440 Make_Attribute_Reference
(Loc
,
1442 New_Occurrence_Of
(Field_Typ
, Loc
),
1443 Attribute_Name
=> Nam
,
1444 Expressions
=> New_List
(
1445 Make_Identifier
(Loc
, Name_S
),
1446 Make_Selected_Component
(Loc
,
1447 Prefix
=> Make_Identifier
(Loc
, Name_V
),
1448 Selector_Name
=> New_Occurrence_Of
(C
, Loc
))));
1449 end Make_Field_Attribute
;
1451 ---------------------------
1452 -- Make_Field_Attributes --
1453 ---------------------------
1455 function Make_Field_Attributes
(Clist
: List_Id
) return List_Id
is
1462 if Present
(Clist
) then
1463 Item
:= First
(Clist
);
1465 -- Loop through components, skipping all internal components,
1466 -- which are not part of the value (e.g. _Tag), except that we
1467 -- don't skip the _Parent, since we do want to process that
1468 -- recursively. If _Parent is an interface type, being abstract
1469 -- with no components there is no need to handle it.
1471 while Present
(Item
) loop
1472 if Nkind
(Item
) = N_Component_Declaration
1474 ((Chars
(Defining_Identifier
(Item
)) = Name_uParent
1475 and then not Is_Interface
1476 (Etype
(Defining_Identifier
(Item
))))
1478 not Is_Internal_Name
(Chars
(Defining_Identifier
(Item
))))
1482 Make_Field_Attribute
(Defining_Identifier
(Item
)));
1490 end Make_Field_Attributes
;
1492 -- Start of processing for Build_Record_Read_Write_Procedure
1495 -- For the protected type case, use corresponding record
1497 if Is_Protected_Type
(Typ
) then
1498 Typt
:= Corresponding_Record_Type
(Typ
);
1503 -- Note that we do nothing with the discriminants, since Read and
1504 -- Write do not read or write the discriminant values. All handling
1505 -- of discriminants occurs in the Input and Output subprograms.
1507 Rdef
:= Type_Definition
1508 (Declaration_Node
(Base_Type
(Underlying_Type
(Typt
))));
1511 -- In record extension case, the fields we want, including the _Parent
1512 -- field representing the parent type, are to be found in the extension.
1513 -- Note that we will naturally process the _Parent field using the type
1514 -- of the parent, and hence its stream attributes, which is appropriate.
1516 if Nkind
(Rdef
) = N_Derived_Type_Definition
then
1517 Rdef
:= Record_Extension_Part
(Rdef
);
1519 if Is_Limited_Type
(Typt
) then
1520 In_Limited_Extension
:= True;
1524 if Present
(Component_List
(Rdef
)) then
1525 Append_List_To
(Stms
,
1526 Make_Component_List_Attributes
(Component_List
(Rdef
)));
1529 Build_Stream_Procedure
1530 (Loc
, Typ
, Decl
, Pnam
, Stms
, Nam
= Name_Read
);
1531 end Build_Record_Read_Write_Procedure
;
1533 ----------------------------------
1534 -- Build_Record_Write_Procedure --
1535 ----------------------------------
1537 procedure Build_Record_Write_Procedure
1541 Pnam
: out Entity_Id
)
1544 Pnam
:= Make_Stream_Subprogram_Name
(Loc
, Typ
, TSS_Stream_Write
);
1545 Build_Record_Read_Write_Procedure
(Loc
, Typ
, Decl
, Pnam
, Name_Write
);
1546 end Build_Record_Write_Procedure
;
1548 -------------------------------
1549 -- Build_Stream_Attr_Profile --
1550 -------------------------------
1552 function Build_Stream_Attr_Profile
1555 Nam
: TSS_Name_Type
) return List_Id
1560 -- (Ada 2005: AI-441): Set the null-excluding attribute because it has
1561 -- no semantic meaning in Ada 95 but it is a requirement in Ada2005.
1563 Profile
:= New_List
(
1564 Make_Parameter_Specification
(Loc
,
1565 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_S
),
1567 Make_Access_Definition
(Loc
,
1568 Null_Exclusion_Present
=> True,
1569 Subtype_Mark
=> New_Reference_To
(
1570 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
)), Loc
))));
1572 if Nam
/= TSS_Stream_Input
then
1574 Make_Parameter_Specification
(Loc
,
1575 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
1576 Out_Present
=> (Nam
= TSS_Stream_Read
),
1577 Parameter_Type
=> New_Reference_To
(Typ
, Loc
)));
1581 end Build_Stream_Attr_Profile
;
1583 ---------------------------
1584 -- Build_Stream_Function --
1585 ---------------------------
1587 procedure Build_Stream_Function
1598 -- Construct function specification
1600 -- (Ada 2005: AI-441): Set the null-excluding attribute because it has
1601 -- no semantic meaning in Ada 95 but it is a requirement in Ada2005.
1604 Make_Function_Specification
(Loc
,
1605 Defining_Unit_Name
=> Fnam
,
1607 Parameter_Specifications
=> New_List
(
1608 Make_Parameter_Specification
(Loc
,
1609 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_S
),
1611 Make_Access_Definition
(Loc
,
1612 Null_Exclusion_Present
=> True,
1613 Subtype_Mark
=> New_Reference_To
(
1614 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
)), Loc
)))),
1616 Result_Definition
=> New_Occurrence_Of
(Typ
, Loc
));
1619 Make_Subprogram_Body
(Loc
,
1620 Specification
=> Spec
,
1621 Declarations
=> Decls
,
1622 Handled_Statement_Sequence
=>
1623 Make_Handled_Sequence_Of_Statements
(Loc
,
1624 Statements
=> Stms
));
1625 end Build_Stream_Function
;
1627 ----------------------------
1628 -- Build_Stream_Procedure --
1629 ----------------------------
1631 procedure Build_Stream_Procedure
1642 -- Construct procedure specification
1644 -- (Ada 2005: AI-441): Set the null-excluding attribute because it has
1645 -- no semantic meaning in Ada 95 but it is a requirement in Ada2005.
1648 Make_Procedure_Specification
(Loc
,
1649 Defining_Unit_Name
=> Pnam
,
1651 Parameter_Specifications
=> New_List
(
1652 Make_Parameter_Specification
(Loc
,
1653 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_S
),
1655 Make_Access_Definition
(Loc
,
1656 Null_Exclusion_Present
=> True,
1657 Subtype_Mark
=> New_Reference_To
(
1658 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
)), Loc
))),
1660 Make_Parameter_Specification
(Loc
,
1661 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
1662 Out_Present
=> Outp
,
1663 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
1666 Make_Subprogram_Body
(Loc
,
1667 Specification
=> Spec
,
1668 Declarations
=> Empty_List
,
1669 Handled_Statement_Sequence
=>
1670 Make_Handled_Sequence_Of_Statements
(Loc
,
1671 Statements
=> Stms
));
1672 end Build_Stream_Procedure
;
1674 -----------------------------
1675 -- Has_Stream_Standard_Rep --
1676 -----------------------------
1678 function Has_Stream_Standard_Rep
(U_Type
: Entity_Id
) return Boolean is
1682 if Has_Non_Standard_Rep
(U_Type
) then
1686 if Has_Stream_Size_Clause
(U_Type
) then
1687 Siz
:= Static_Integer
(Expression
(Stream_Size_Clause
(U_Type
)));
1689 Siz
:= Esize
(First_Subtype
(U_Type
));
1692 return Siz
= Esize
(Root_Type
(U_Type
));
1693 end Has_Stream_Standard_Rep
;
1695 ---------------------------------
1696 -- Make_Stream_Subprogram_Name --
1697 ---------------------------------
1699 function Make_Stream_Subprogram_Name
1702 Nam
: TSS_Name_Type
) return Entity_Id
1707 -- For tagged types, we are dealing with a TSS associated with the
1708 -- declaration, so we use the standard primitive function name. For
1709 -- other types, generate a local TSS name since we are generating
1710 -- the subprogram at the point of use.
1712 if Is_Tagged_Type
(Typ
) then
1713 Sname
:= Make_TSS_Name
(Typ
, Nam
);
1715 Sname
:= Make_TSS_Name_Local
(Typ
, Nam
);
1718 return Make_Defining_Identifier
(Loc
, Sname
);
1719 end Make_Stream_Subprogram_Name
;
1721 ----------------------
1722 -- Stream_Base_Type --
1723 ----------------------
1725 function Stream_Base_Type
(E
: Entity_Id
) return Entity_Id
is
1727 if Is_Array_Type
(E
)
1728 and then Is_First_Subtype
(E
)
1732 return Base_Type
(E
);
1734 end Stream_Base_Type
;