1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Atree
; use Atree
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Exp_Util
; use Exp_Util
;
34 with Sem_Util
; use Sem_Util
;
35 with Sinfo
; use Sinfo
;
36 with Snames
; use Snames
;
38 package body Exp_Tss
is
44 function Base_Init_Proc
(Typ
: Entity_Id
) return Entity_Id
is
49 pragma Assert
(Ekind
(Typ
) in Type_Kind
);
51 if Is_Private_Type
(Typ
) then
52 Full_Type
:= Underlying_Type
(Base_Type
(Typ
));
57 if No
(Full_Type
) then
59 elsif Is_Concurrent_Type
(Full_Type
)
60 and then Present
(Corresponding_Record_Type
(Base_Type
(Full_Type
)))
62 return Init_Proc
(Corresponding_Record_Type
(Base_Type
(Full_Type
)));
65 Proc
:= Init_Proc
(Base_Type
(Full_Type
));
68 and then Is_Composite_Type
(Full_Type
)
69 and then Is_Derived_Type
(Full_Type
)
71 return Init_Proc
(Root_Type
(Full_Type
));
82 -- Note: internally this routine is also used to initially set up
83 -- a TSS entry for a new type (case of being called from Set_TSS)
85 procedure Copy_TSS
(TSS
: Entity_Id
; Typ
: Entity_Id
) is
89 Ensure_Freeze_Node
(Typ
);
90 FN
:= Freeze_Node
(Typ
);
92 if No
(TSS_Elist
(FN
)) then
93 Set_TSS_Elist
(FN
, New_Elmt_List
);
96 -- We prepend here, so that a second call overrides the first, it
97 -- is not clear that this is required, but it seems reasonable.
99 Prepend_Elmt
(TSS
, TSS_Elist
(FN
));
102 ---------------------------------
103 -- Has_Non_Null_Base_Init_Proc --
104 ---------------------------------
106 function Has_Non_Null_Base_Init_Proc
(Typ
: Entity_Id
) return Boolean is
107 BIP
: constant Entity_Id
:= Base_Init_Proc
(Typ
);
110 return Present
(BIP
) and then not Is_Null_Init_Proc
(BIP
);
111 end Has_Non_Null_Base_Init_Proc
;
117 function Init_Proc
(Typ
: Entity_Id
) return Entity_Id
is
119 return TSS
(Typ
, Name_uInit_Proc
);
126 procedure Set_Init_Proc
(Typ
: Entity_Id
; Init
: Entity_Id
) is
135 procedure Set_TSS
(Typ
: Entity_Id
; TSS
: Entity_Id
) is
136 Subprog_Body
: constant Node_Id
:= Unit_Declaration_Node
(TSS
);
139 -- Case of insertion location is in unit defining the type
141 if In_Same_Code_Unit
(Typ
, TSS
) then
142 Append_Freeze_Action
(Typ
, Subprog_Body
);
144 -- Otherwise, we are using an already existing TSS in another unit
157 function TSS
(Typ
: Entity_Id
; Nam
: Name_Id
) return Entity_Id
is
158 FN
: constant Node_Id
:= Freeze_Node
(Typ
);
166 elsif No
(TSS_Elist
(FN
)) then
170 Elmt
:= First_Elmt
(TSS_Elist
(FN
));
172 while Present
(Elmt
) loop
173 if Chars
(Node
(Elmt
)) = Nam
then
176 -- For stream subprograms, the TSS entity may be a renaming-
177 -- as-body of an already generated entity. Use that one rather
178 -- the one introduced by the renaming, which is an artifact of
179 -- current stream handling.
181 if Nkind
(Parent
(Parent
(Subp
))) =
182 N_Subprogram_Renaming_Declaration
184 Present
(Corresponding_Spec
(Parent
(Parent
(Subp
))))
186 return Corresponding_Spec
(Parent
(Parent
(Subp
)));