summaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch3.adb
diff options
context:
space:
mode:
authorbosch <bosch@138bc75d-0d04-0410-961f-82ee72b054a4>2002-03-08 20:11:04 +0000
committerbosch <bosch@138bc75d-0d04-0410-961f-82ee72b054a4>2002-03-08 20:11:04 +0000
commitf15731c43ae5e8cea424ea40f905c19afa1bd2e4 (patch)
treeb584a79288c93215b05fb451943291ccd039388b /gcc/ada/exp_ch3.adb
parent1d347c236ad815c77bd345611ed221b0bd6091de (diff)
downloadgcc-f15731c43ae5e8cea424ea40f905c19afa1bd2e4.tar.gz
* 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads,
4dintnam.ads, 4gintnam.ads, 4hintnam.ads, 4lintnam.ads, 4mintnam.ads, 4pintnam.ads, 4rintnam.ads, 4sintnam.ads, 4uintnam.ads, 4vcalend.adb, 4zintnam.ads, 52system.ads, 5amastop.adb, 5asystem.ads, 5ataprop.adb, 5atpopsp.adb, 5avxwork.ads, 5bosinte.adb, 5bsystem.ads, 5esystem.ads, 5fsystem.ads, 5ftaprop.adb, 5ginterr.adb, 5gmastop.adb, 5gsystem.ads, 5gtaprop.adb, 5gtasinf.adb, 5gtasinf.ads, 5hparame.ads, 5hsystem.ads, 5htaprop.adb, 5htraceb.adb, 5itaprop.adb, 5ksystem.ads, 5kvxwork.ads, 5lintman.adb, 5lsystem.ads, 5mvxwork.ads, 5ninmaop.adb, 5nosinte.ads, 5ntaprop.adb, 5ointerr.adb, 5omastop.adb, 5oosinte.adb, 5osystem.ads, 5otaprop.adb, 5otaspri.ads, 5pvxwork.ads, 5qtaprop.adb, 5sintman.adb, 5ssystem.ads, 5staprop.adb, 5stpopse.adb, 5svxwork.ads, 5tosinte.ads, 5uintman.adb, 5vasthan.adb, 5vinmaop.adb, 5vinterr.adb, 5vintman.adb, 5vmastop.adb, 5vparame.ads, 5vsystem.ads, 5vtaprop.adb, 5vtpopde.adb, 5wmemory.adb, 5wsystem.ads, 5wtaprop.adb, 5ysystem.ads, 5zinterr.adb, 5zintman.adb, 5zosinte.adb, 5zosinte.ads, 5zsystem.ads, 5ztaprop.adb, 6vcpp.adb, 6vcstrea.adb, 7sintman.adb, 7staprop.adb, 7stpopsp.adb, 9drpc.adb, Make-lang.in, Makefile.in, a-caldel.adb, a-comlin.ads, a-dynpri.adb, a-except.adb, a-except.ads, a-finali.adb, a-ncelfu.ads, a-reatim.adb, a-retide.adb, a-stream.ads, a-ststio.adb, a-ststio.ads, a-stwifi.adb, a-tags.adb, a-tasatt.adb, a-textio.adb, a-tideau.adb, a-tiflau.adb, a-tigeau.adb, a-tigeau.ads, a-tiinau.adb, a-timoau.adb, a-witeio.adb, a-wtdeau.adb, a-wtenau.adb, a-wtflau.adb, a-wtgeau.adb, a-wtgeau.ads, a-wtinau.adb, a-wtmoau.adb, ada-tree.def, ada-tree.h, adaint.c, adaint.h, ali-util.adb, ali.adb, ali.ads, atree.adb, atree.ads, atree.h, back_end.adb, bcheck.adb, bindgen.adb, bindusg.adb, checks.adb, comperr.adb, config-lang.in, csets.adb, csets.ads, cstand.adb, cstreams.c, debug.adb, debug.ads, decl.c, einfo.adb, einfo.ads, einfo.h, elists.h, errout.adb, errout.ads, eval_fat.adb, exp_aggr.adb, exp_attr.adb, exp_ch11.adb, exp_ch12.adb, exp_ch13.adb, exp_ch2.adb, exp_ch3.adb, exp_ch3.ads, exp_ch4.adb, exp_ch5.adb, exp_ch6.adb, exp_ch7.adb, exp_ch7.ads, exp_ch9.adb, exp_ch9.ads, exp_dbug.adb, exp_dbug.ads, exp_disp.ads, exp_dist.adb, exp_fixd.adb, exp_intr.adb, exp_pakd.adb, exp_prag.adb, exp_strm.adb, exp_util.adb, exp_util.ads, expander.adb, expect.c, fe.h, fmap.adb, fmap.ads, fname-uf.adb, freeze.adb, frontend.adb, g-awk.adb, g-cgideb.adb, g-comlin.adb, g-comlin.ads, g-debpoo.adb, g-dirope.adb, g-dirope.ads, g-dyntab.adb, g-expect.adb, g-expect.ads, g-io.ads, g-io_aux.adb, g-io_aux.ads, g-locfil.adb, g-locfil.ads, g-os_lib.adb, g-os_lib.ads, g-regexp.adb, g-regpat.adb, g-socket.adb, g-socket.ads, g-spipat.adb, g-table.adb, g-trasym.adb, g-trasym.ads, gigi.h, gmem.c, gnat1drv.adb, gnatbind.adb, gnatbl.c, gnatchop.adb, gnatcmd.adb, gnatdll.adb, gnatfind.adb, gnatlbr.adb, gnatlink.adb, gnatls.adb, gnatmem.adb, gnatprep.adb, gnatvsn.ads, gnatxref.adb, hlo.adb, hostparm.ads, i-cobol.adb, i-cpp.adb, i-cstrea.ads, i-cstrin.adb, i-pacdec.adb, i-vxwork.ads, impunit.adb, init.c, inline.adb, io-aux.c, layout.adb, lib-load.adb, lib-util.adb, lib-writ.adb, lib-writ.ads, lib-xref.adb, lib-xref.ads, lib.adb, lib.ads, make.adb, makeusg.adb, mdll.adb, memroot.adb, misc.c, mlib-tgt.adb, mlib-utl.adb, mlib-utl.ads, mlib.adb, namet.adb, namet.ads, namet.h, nlists.h, nmake.adb, nmake.ads, nmake.adt, opt.adb, opt.ads, osint.adb, osint.ads, output.adb, output.ads, par-ch2.adb, par-ch3.adb, par-ch5.adb, par-prag.adb, par-tchk.adb, par-util.adb, par.adb, prj-attr.adb, prj-dect.adb, prj-env.adb, prj-env.ads, prj-nmsc.adb, prj-part.adb, prj-proc.adb, prj-strt.adb, prj-tree.adb, prj-tree.ads, prj.adb, prj.ads, raise.c, raise.h, repinfo.adb, restrict.adb, restrict.ads, rident.ads, rtsfind.adb, rtsfind.ads, s-arit64.adb, s-asthan.adb, s-atacco.adb, s-atacco.ads, s-auxdec.adb, s-crc32.adb, s-crc32.ads, s-direio.adb, s-fatgen.adb, s-fileio.adb, s-finimp.adb, s-gloloc.adb, s-gloloc.ads, s-interr.adb, s-mastop.adb, s-mastop.ads, s-memory.adb, s-parame.ads, s-parint.adb, s-pooglo.adb, s-pooloc.adb, s-rpc.adb, s-secsta.adb, s-sequio.adb, s-shasto.adb, s-soflin.adb, s-soflin.ads, s-stache.adb, s-taasde.adb, s-taasde.ads, s-tadeca.adb, s-tadeca.ads, s-tadert.adb, s-tadert.ads, s-taenca.adb, s-taenca.ads, s-taprob.adb, s-taprop.ads, s-tarest.adb, s-tasdeb.adb, s-tasini.adb, s-tasini.ads, s-taskin.adb, s-taskin.ads, s-tasque.adb, s-tasque.ads, s-tasren.adb, s-tasren.ads, s-tassta.adb, s-tasuti.adb, s-tasuti.ads, s-tataat.adb, s-tataat.ads, s-tpoben.adb, s-tpoben.ads, s-tpobop.adb, s-tposen.adb, s-tposen.ads, s-traceb.adb, s-traceb.ads, s-unstyp.ads, s-widenu.adb, scn-nlit.adb, scn.adb, sem.adb, sem_aggr.adb, sem_attr.adb, sem_attr.ads, sem_case.adb, sem_ch10.adb, sem_ch11.adb, sem_ch11.ads, sem_ch12.adb, sem_ch13.adb, sem_ch13.ads, sem_ch2.adb, sem_ch3.adb, sem_ch3.ads, sem_ch4.adb, sem_ch5.adb, sem_ch6.adb, sem_ch6.ads, sem_ch7.adb, sem_ch8.adb, sem_ch8.ads, sem_ch9.adb, sem_disp.adb, sem_dist.adb, sem_elab.adb, sem_elim.adb, sem_elim.ads, sem_eval.adb, sem_intr.adb, sem_mech.adb, sem_prag.adb, sem_res.adb, sem_type.adb, sem_util.adb, sem_util.ads, sem_vfpt.adb, sem_warn.adb, sinfo.adb, sinfo.ads, sinfo.h, sinput-l.adb, sinput-l.ads, sinput.adb, sinput.ads, snames.adb, snames.ads, snames.h, sprint.adb, sprint.ads, stringt.adb, stringt.ads, stringt.h, style.adb, switch.adb, switch.ads, sysdep.c, system.ads, table.adb, targparm.adb, targparm.ads, targtyps.c, tbuild.adb, tbuild.ads, tracebak.c, trans.c, tree_gen.adb, tree_io.adb, treepr.adb, treepr.ads, treeprs.ads, treeprs.adt, ttypes.ads, types.adb, types.ads, types.h, uintp.ads, urealp.ads, usage.adb, utils.c, utils2.c, validsw.adb, xnmake.adb, xr_tabls.adb, xr_tabls.ads, xref_lib.adb, xref_lib.ads : Merge in ACT changes. * 1ssecsta.adb, 1ssecsta.ads, a-chlat9.ads, a-cwila9.ads, g-enblsp.adb, g-md5.adb, g-md5.ads, gnatname.adb, gnatname.ads, mkdir.c, osint-b.adb, osint-b.ads, osint-c.adb, osint-c.ads, osint-l.adb, osint-l.ads, osint-m.adb, osint-m.ads : New files * 3lsoccon.ads, 5qparame.ads, 5qvxwork.ads, 5smastop.adb, 5zparame.ads, gnatmain.adb, gnatmain.ads, gnatpsys.adb : Removed * mdllfile.adb, mdllfile.ads, mdlltool.adb, mdlltool.ads : Renamed to mdll-fil.ad[bs] and mdll-util.ad[bs] * mdll-fil.adb, mdll-fil.ads, mdll-utl.adb, mdll-utl.ads : Renamed from mdllfile.ad[bs] and mdlltool.ad[bs] git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@50451 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/exp_ch3.adb')
-rw-r--r--gcc/ada/exp_ch3.adb275
1 files changed, 189 insertions, 86 deletions
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 22d84263da1..7a39b4c9380 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -6,9 +6,9 @@
-- --
-- B o d y --
-- --
--- $Revision: 1.2 $
+-- $Revision$
-- --
--- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -30,6 +30,7 @@ with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Elists; use Elists;
+with Errout; use Errout;
with Exp_Aggr; use Exp_Aggr;
with Exp_Ch4; use Exp_Ch4;
with Exp_Ch7; use Exp_Ch7;
@@ -118,6 +119,11 @@ package body Exp_Ch3 is
-- Create An Equality function for the non-tagged variant record 'Typ'
-- and attach it to the TSS list
+ procedure Check_Stream_Attributes (Typ : Entity_Id);
+ -- Check that if a limited extension has a parent with user-defined
+ -- stream attributes, any limited component of the extension also has
+ -- the corresponding user-defined stream attributes.
+
procedure Expand_Tagged_Root (T : Entity_Id);
-- Add a field _Tag at the beginning of the record. This field carries
-- the value of the access to the Dispatch table. This procedure is only
@@ -147,6 +153,10 @@ package body Exp_Ch3 is
-- applies only to E_Record_Type entities, not to class wide types,
-- record subtypes, or private types.
+ procedure Freeze_Stream_Operations (N : Node_Id; Typ : Entity_Id);
+ -- Treat user-defined stream operations as renaming_as_body if the
+ -- subprogram they rename is not frozen when the type is frozen.
+
function Init_Formals (Typ : Entity_Id) return List_Id;
-- This function builds the list of formals for an initialization routine.
-- The first formal is always _Init with the given type. For task value
@@ -561,7 +571,6 @@ package body Exp_Ch3 is
Set_Ekind (Proc_Id, E_Procedure);
Set_Is_Public (Proc_Id, Is_Public (A_Type));
- Set_Is_Inlined (Proc_Id);
Set_Is_Internal (Proc_Id);
Set_Has_Completion (Proc_Id);
@@ -569,6 +578,17 @@ package body Exp_Ch3 is
Set_Debug_Info_Off (Proc_Id);
end if;
+ -- Set inlined unless controlled stuff or tasks around, in which
+ -- case we do not want to inline, because nested stuff may cause
+ -- difficulties in interunit inlining, and furthermore there is
+ -- in any case no point in inlining such complex init procs.
+
+ if not Has_Task (Proc_Id)
+ and then not Controlled_Type (Proc_Id)
+ then
+ Set_Is_Inlined (Proc_Id);
+ end if;
+
-- Associate Init_Proc with type, and determine if the procedure
-- is null (happens because of the Initialize_Scalars pragma case,
-- where we have to generate a null procedure in case it is called
@@ -1325,14 +1345,10 @@ package body Exp_Ch3 is
-- of the initialization procedure (by calling all the preceding
-- auxiliary routines), and install it as the _init TSS.
- procedure Build_Record_Checks
- (S : Node_Id;
- Related_Nod : Node_Id;
- Check_List : List_Id);
+ procedure Build_Record_Checks (S : Node_Id; Check_List : List_Id);
-- Add range checks to components of disciminated records. S is a
- -- subtype indication of a record component. Related_Nod is passed
- -- for compatibility with Process_Range_Expr_In_Decl. Check_List is
- -- a list to which the check actions are appended.
+ -- subtype indication of a record component. Check_List is a list
+ -- to which the check actions are appended.
function Component_Needs_Simple_Initialization
(T : Entity_Id)
@@ -1345,20 +1361,17 @@ package body Exp_Ch3 is
-- initialized by other means.
procedure Constrain_Array
- (SI : Node_Id;
- Related_Nod : Node_Id;
- Check_List : List_Id);
+ (SI : Node_Id;
+ Check_List : List_Id);
-- Called from Build_Record_Checks.
-- Apply a list of index constraints to an unconstrained array type.
-- The first parameter is the entity for the resulting subtype.
- -- Related_Nod is passed for compatibility with Process_Range_Expr_In_
- -- Decl. Check_List is a list to which the check actions are appended.
+ -- Check_List is a list to which the check actions are appended.
procedure Constrain_Index
- (Index : Node_Id;
- S : Node_Id;
- Related_Nod : Node_Id;
- Check_List : List_Id);
+ (Index : Node_Id;
+ S : Node_Id;
+ Check_List : List_Id);
-- Called from Build_Record_Checks.
-- Process an index constraint in a constrained array declaration.
-- The constraint can be a subtype name, or a range with or without
@@ -1864,10 +1877,7 @@ package body Exp_Ch3 is
Decl := First_Non_Pragma (Component_Items (Comp_List));
while Present (Decl) loop
Loc := Sloc (Decl);
- Build_Record_Checks
- (Subtype_Indication (Decl),
- Decl,
- Check_List);
+ Build_Record_Checks (Subtype_Indication (Decl), Check_List);
Id := Defining_Identifier (Decl);
Typ := Etype (Id);
@@ -2065,15 +2075,11 @@ package body Exp_Ch3 is
-- Build_Record_Checks --
-------------------------
- procedure Build_Record_Checks
- (S : Node_Id;
- Related_Nod : Node_Id;
- Check_List : List_Id)
- is
+ procedure Build_Record_Checks (S : Node_Id; Check_List : List_Id) is
P : Node_Id;
Subtype_Mark_Id : Entity_Id;
- begin
+ begin
if Nkind (S) = N_Subtype_Indication then
Find_Type (Subtype_Mark (S));
P := Parent (S);
@@ -2084,13 +2090,12 @@ package body Exp_Ch3 is
case Ekind (Subtype_Mark_Id) is
when Array_Kind =>
- Constrain_Array (S, Related_Nod, Check_List);
+ Constrain_Array (S, Check_List);
when others =>
null;
end case;
end if;
-
end Build_Record_Checks;
-------------------------------------------
@@ -2114,7 +2119,6 @@ package body Exp_Ch3 is
procedure Constrain_Array
(SI : Node_Id;
- Related_Nod : Node_Id;
Check_List : List_Id)
is
C : constant Node_Id := Constraint (SI);
@@ -2148,7 +2152,7 @@ package body Exp_Ch3 is
-- Apply constraints to each index type
for J in 1 .. Number_Of_Constraints loop
- Constrain_Index (Index, S, Related_Nod, Check_List);
+ Constrain_Index (Index, S, Check_List);
Next (Index);
Next (S);
end loop;
@@ -2162,14 +2166,13 @@ package body Exp_Ch3 is
procedure Constrain_Index
(Index : Node_Id;
S : Node_Id;
- Related_Nod : Node_Id;
Check_List : List_Id)
is
T : constant Entity_Id := Etype (Index);
begin
if Nkind (S) = N_Range then
- Process_Range_Expr_In_Decl (S, T, Related_Nod, Check_List);
+ Process_Range_Expr_In_Decl (S, T, Check_List);
end if;
end Constrain_Index;
@@ -2376,8 +2379,10 @@ package body Exp_Ch3 is
-- yet. The initialization of controlled records contains a nested
-- clean-up procedure that makes it impractical to inline as well,
-- and leads to undefined symbols if inlined in a different unit.
+ -- Similar considerations apply to task types.
- if not Is_Protected_Record_Type (Rec_Type)
+ if not Is_Concurrent_Type (Rec_Type)
+ and then not Has_Task (Rec_Type)
and then not Controlled_Type (Rec_Type)
then
Set_Is_Inlined (Proc_Id);
@@ -2482,8 +2487,8 @@ package body Exp_Ch3 is
if Has_Unchecked_Union (Typ) then
Append_To (Stmts,
- Make_Raise_Program_Error (Loc));
-
+ Make_Raise_Program_Error (Loc,
+ Reason => PE_Unchecked_Union_Restriction));
else
Append_To (Stmts,
Make_Eq_If (Typ,
@@ -2504,6 +2509,41 @@ package body Exp_Ch3 is
end if;
end Build_Variant_Record_Equality;
+ -----------------------------
+ -- Check_Stream_Attributes --
+ -----------------------------
+
+ procedure Check_Stream_Attributes (Typ : Entity_Id) is
+ Comp : Entity_Id;
+ Par : constant Entity_Id := Root_Type (Base_Type (Typ));
+ Par_Read : Boolean := Present (TSS (Par, Name_uRead));
+ Par_Write : Boolean := Present (TSS (Par, Name_uWrite));
+
+ begin
+ if Par_Read or else Par_Write then
+ Comp := First_Component (Typ);
+ while Present (Comp) loop
+ if Comes_From_Source (Comp)
+ and then Original_Record_Component (Comp) = Comp
+ and then Is_Limited_Type (Etype (Comp))
+ then
+ if (Par_Read and then
+ No (TSS (Base_Type (Etype (Comp)), Name_uRead)))
+ or else
+ (Par_Write and then
+ No (TSS (Base_Type (Etype (Comp)), Name_uWrite)))
+ then
+ Error_Msg_N
+ ("|component must have Stream attribute",
+ Parent (Comp));
+ end if;
+ end if;
+
+ Next_Component (Comp);
+ end loop;
+ end if;
+ end Check_Stream_Attributes;
+
---------------------------
-- Expand_Derived_Record --
---------------------------
@@ -2679,7 +2719,7 @@ package body Exp_Ch3 is
end if;
elsif Has_Task (Def_Id) then
- Expand_Previous_Access_Type (N, Def_Id);
+ Expand_Previous_Access_Type (Def_Id);
end if;
Par_Id := Etype (B_Id);
@@ -2757,10 +2797,19 @@ package body Exp_Ch3 is
Expr_Q : Node_Id;
begin
+ -- If we have a task type in no run time mode, then complain and ignore
+
+ if No_Run_Time
+ and then not Restricted_Profile
+ and then Is_Task_Type (Typ)
+ then
+ Disallow_In_No_Run_Time_Mode (N);
+ return;
+
-- Don't do anything for deferred constants. All proper actions will
-- be expanded during the redeclaration.
- if No (Expr) and Constant_Present (N) then
+ elsif No (Expr) and Constant_Present (N) then
return;
end if;
@@ -2870,6 +2919,14 @@ package body Exp_Ch3 is
Insert_Actions_After (N,
Build_Initialization_Call (Loc, Id_Ref, Typ));
+ -- The initialization call may well set Not_Source_Assigned
+ -- to False, because it looks like an modification, but the
+ -- proper criterion is whether or not the type is at least
+ -- partially initialized, so reset the flag appropriately.
+
+ Set_Not_Source_Assigned
+ (Def_Id, not Is_Partially_Initialized_Type (Typ));
+
-- If simple initialization is required, then set an appropriate
-- simple initialization expression in place. This special
-- initialization is required even though No_Init_Flag is present.
@@ -3076,7 +3133,7 @@ package body Exp_Ch3 is
-- Expand_Previous_Access_Type --
---------------------------------
- procedure Expand_Previous_Access_Type (N : Node_Id; Def_Id : Entity_Id) is
+ procedure Expand_Previous_Access_Type (Def_Id : Entity_Id) is
T : Entity_Id := First_Entity (Current_Scope);
begin
@@ -3456,7 +3513,8 @@ package body Exp_Ch3 is
Discrete_Choices => New_List (Make_Others_Choice (Loc)),
Statements => New_List (
Make_Raise_Program_Error (Loc,
- Condition => Make_Identifier (Loc, Name_uF)),
+ Condition => Make_Identifier (Loc, Name_uF),
+ Reason => PE_Invalid_Data),
Make_Return_Statement (Loc,
Expression =>
Make_Integer_Literal (Loc, -1)))));
@@ -3568,6 +3626,13 @@ package body Exp_Ch3 is
end;
end if;
+ if Is_Derived_Type (Def_Id)
+ and then Is_Limited_Type (Def_Id)
+ and then Is_Tagged_Type (Def_Id)
+ then
+ Check_Stream_Attributes (Def_Id);
+ end if;
+
-- Update task and controlled component flags, because some of the
-- component types may have been private at the point of the record
-- declaration.
@@ -3760,6 +3825,40 @@ package body Exp_Ch3 is
end Freeze_Record_Type;
+ ------------------------------
+ -- Freeze_Stream_Operations --
+ ------------------------------
+
+ procedure Freeze_Stream_Operations (N : Node_Id; Typ : Entity_Id) is
+ Names : constant array (1 .. 4) of Name_Id :=
+ (Name_uInput, Name_uOutput, Name_uRead, Name_uWrite);
+ Stream_Op : Entity_Id;
+
+ begin
+ -- Primitive operations of tagged types are frozen when the dispatch
+ -- table is constructed.
+
+ if not Comes_From_Source (Typ)
+ or else Is_Tagged_Type (Typ)
+ then
+ return;
+ end if;
+
+ for J in Names'Range loop
+ Stream_Op := TSS (Typ, Names (J));
+
+ if Present (Stream_Op)
+ and then Is_Subprogram (Stream_Op)
+ and then Nkind (Unit_Declaration_Node (Stream_Op)) =
+ N_Subprogram_Declaration
+ and then not Is_Frozen (Stream_Op)
+ then
+ Append_Freeze_Actions
+ (Typ, Freeze_Entity (Stream_Op, Sloc (N)));
+ end if;
+ end loop;
+ end Freeze_Stream_Operations;
+
-----------------
-- Freeze_Type --
-----------------
@@ -3974,7 +4073,6 @@ package body Exp_Ch3 is
-- Third discriminant is the alignment
DT_Align)))));
-
end;
Set_Associated_Storage_Pool (Def_Id, Pool_Object);
@@ -3990,7 +4088,6 @@ package body Exp_Ch3 is
-- when analyzing the rep. clause
null;
-
end if;
-- For access-to-controlled types (including class-wide types
@@ -4078,6 +4175,8 @@ package body Exp_Ch3 is
-- the freeze nodes are there for use by Gigi.
end if;
+
+ Freeze_Stream_Operations (N, Def_Id);
end Freeze_Type;
-------------------------
@@ -4095,9 +4194,34 @@ package body Exp_Ch3 is
Val_RE : RE_Id;
begin
+ -- For a private type, we should always have an underlying type
+ -- (because this was already checked in Needs_Simple_Initialization).
+ -- What we do is to get the value for the underlying type and then
+ -- do an Unchecked_Convert to the private type.
+
+ if Is_Private_Type (T) then
+ Val := Get_Simple_Init_Val (Underlying_Type (T), Loc);
+
+ -- A special case, if the underlying value is null, then qualify
+ -- it with the underlying type, so that the null is properly typed
+ -- Similarly, if it is an aggregate it must be qualified, because
+ -- an unchecked conversion does not provide a context for it.
+
+ if Nkind (Val) = N_Null
+ or else Nkind (Val) = N_Aggregate
+ then
+ Val :=
+ Make_Qualified_Expression (Loc,
+ Subtype_Mark =>
+ New_Occurrence_Of (Underlying_Type (T), Loc),
+ Expression => Val);
+ end if;
+
+ return Unchecked_Convert_To (T, Val);
+
-- For scalars, we must have normalize/initialize scalars case
- if Is_Scalar_Type (T) then
+ elsif Is_Scalar_Type (T) then
pragma Assert (Init_Or_Norm_Scalars);
-- Processing for Normalize_Scalars case
@@ -4248,33 +4372,12 @@ package body Exp_Ch3 is
return Nod;
end;
- -- Otherwise we have a case of a private type whose underlying type
- -- needs simple initialization. In this case, we get the value for
- -- the underlying type, then unchecked convert to the private type.
+ -- No other possibilities should arise, since we should only be
+ -- calling Get_Simple_Init_Val if Needs_Simple_Initialization
+ -- returned True, indicating one of the above cases held.
else
- pragma Assert
- (Is_Private_Type (T)
- and then Present (Underlying_Type (T)));
-
- Val := Get_Simple_Init_Val (Underlying_Type (T), Loc);
-
- -- A special case, if the underlying value is null, then qualify
- -- it with the underlying type, so that the null is properly typed
- -- Similarly, if it is an aggregate it must be qualified, because
- -- an unchecked conversion does not provide a context for it.
-
- if Nkind (Val) = N_Null
- or else Nkind (Val) = N_Aggregate
- then
- Val :=
- Make_Qualified_Expression (Loc,
- Subtype_Mark =>
- New_Occurrence_Of (Underlying_Type (T), Loc),
- Expression => Val);
- end if;
-
- return Unchecked_Convert_To (T, Val);
+ raise Program_Error;
end if;
end Get_Simple_Init_Val;
@@ -4718,11 +4821,26 @@ package body Exp_Ch3 is
function Needs_Simple_Initialization (T : Entity_Id) return Boolean is
begin
+ -- Check for private type, in which case test applies to the
+ -- underlying type of the private type.
+
+ if Is_Private_Type (T) then
+ declare
+ RT : constant Entity_Id := Underlying_Type (T);
+
+ begin
+ if Present (RT) then
+ return Needs_Simple_Initialization (RT);
+ else
+ return False;
+ end if;
+ end;
+
-- Cases needing simple initialization are access types, and, if pragma
-- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
-- types.
- if Is_Access_Type (T)
+ elsif Is_Access_Type (T)
or else (Init_Or_Norm_Scalars and then (Is_Scalar_Type (T)))
or else (Is_Bit_Packed_Array (T)
@@ -4745,21 +4863,6 @@ package body Exp_Ch3 is
then
return True;
- -- Check for private type, in which case test applies to the
- -- underlying type of the private type.
-
- elsif Is_Private_Type (T) then
- declare
- RT : constant Entity_Id := Underlying_Type (T);
-
- begin
- if Present (RT) then
- return Needs_Simple_Initialization (RT);
- else
- return False;
- end if;
- end;
-
else
return False;
end if;