]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/exp_tss.ads
[Ada] Bump copyright year
[thirdparty/gcc.git] / gcc / ada / exp_tss.ads
CommitLineData
70482933
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- E X P _ T S S --
6-- --
7-- S p e c --
8-- --
4b490c1e 9-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
70482933
RK
10-- --
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- --
b5c84c3c 13-- ware Foundation; either version 3, or (at your option) any later ver- --
70482933
RK
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 --
b5c84c3c
RD
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. --
70482933
RK
20-- --
21-- GNAT was originally developed by the GNAT team at New York University. --
71ff80dc 22-- Extensive contributions were provided by Ada Core Technologies Inc. --
70482933
RK
23-- --
24------------------------------------------------------------------------------
25
26-- Type Support Subprogram (TSS) handling
27
39f4e199 28with Namet; use Namet;
70482933
RK
29with Types; use Types;
30
31package Exp_Tss is
32
33 -- A type support subprogram (TSS) is an internally generated function or
34 -- procedure that is associated with a particular type. Examples are the
35 -- implicit initialization procedure, and subprograms for the Input and
36 -- Output attributes.
37
38 -- A given TSS is either generated once at the point of the declaration of
39 -- the type, or it is generated as needed in clients, but only one copy is
40 -- required in any one generated object file. The choice between these two
41 -- possibilities is made on a TSS-by-TSS basis depending on the estimation
42 -- of how likely the TSS is to be used. Initialization procedures fall in
43 -- the first category, for example, since it is likely that any declared
44 -- type will be used in a context requiring initialization, but the stream
45 -- attributes use the second approach, since it is more likely that they
46 -- will not be used at all, or will only be used in one client in any case.
47
fbf5a39b
AC
48 -------------------------
49 -- Current Limitations --
50 -------------------------
51
52 -- In the current version of this package, only the case of generating a
e14c931f 53 -- TSS at the point of declaration of the type is accommodated. A clear
fbf5a39b 54 -- improvement would be to follow through with the full implementation
e14c931f 55 -- as described above, and also accommodate the requirement of generating
fbf5a39b
AC
56 -- only one copy in a given object file.
57
58 -- For now, we deal with the local case by generating duplicate versions
59 -- of the TSS routine, which is clearly rather inefficient in space usage.
60 -- This is done by using Make_TSS_Name_Local to generate unique names
61 -- for the different instances of TSS routines in a given scope.
62
63 ----------------
64 -- TSS Naming --
65 ----------------
66
edd63e9b
ES
67 -- A TSS is identified by its Chars name. The name has the form typXY or
68 -- typ_<serial>XY, where typ is the type name, and XY are two characters
69 -- that identify the particular TSS routine. A unique serial number is
70 -- included for the case where several local instances of the same TSS
71 -- must be generated (see discussion under Make_TSS_Name_Local).
72
73 -- The following codes are used to denote TSSs:
fbf5a39b 74
1d1bd8ad
AC
75 -- Note: When making additions to this list, make the corresponding change
76 -- to the list in snames.adb-tmpl.
fbf5a39b
AC
77
78 type TSS_Name_Type is new String (1 .. 2);
79 subtype TNT is TSS_Name_Type;
80
81 TSS_Deep_Adjust : constant TNT := "DA"; -- Deep Adjust
82 TSS_Deep_Finalize : constant TNT := "DF"; -- Deep Finalize
83 TSS_Deep_Initialize : constant TNT := "DI"; -- Deep Initialize
84 TSS_Composite_Equality : constant TNT := "EQ"; -- Composite Equality
df3e68b1 85 TSS_Finalize_Address : constant TNT := "FD"; -- Finalize Address
6e40e481 86 TSS_From_Any : constant TNT := "FA"; -- PolyORB/DSA From_Any
fbf5a39b 87 TSS_Init_Proc : constant TNT := "IP"; -- Initialization Procedure
cefce34c 88 TSS_CPP_Init_Proc : constant TNT := "IC"; -- Init C++ dispatch tables
6e40e481 89 TSS_RAS_Access : constant TNT := "RA"; -- RAS type access
09494c32 90 TSS_RAS_Dereference : constant TNT := "RD"; -- RAS type dereference
fbf5a39b 91 TSS_Rep_To_Pos : constant TNT := "RP"; -- Rep to Pos conversion
26fd4eae 92 TSS_Slice_Assign : constant TNT := "SA"; -- Slice assignment
fbf5a39b
AC
93 TSS_Stream_Input : constant TNT := "SI"; -- Stream Input attribute
94 TSS_Stream_Output : constant TNT := "SO"; -- Stream Output attribute
95 TSS_Stream_Read : constant TNT := "SR"; -- Stream Read attribute
96 TSS_Stream_Write : constant TNT := "SW"; -- Stream Write attribute
6e40e481
TQ
97 TSS_To_Any : constant TNT := "TA"; -- PolyORB/DSA To_Any
98 TSS_TypeCode : constant TNT := "TC"; -- PolyORB/DSA TypeCode
fbf5a39b 99
6e40e481
TQ
100 -- The array below contains all valid TSS names
101
102 TSS_Names : constant array (Natural range <>) of TSS_Name_Type :=
fbf5a39b
AC
103 (TSS_Deep_Adjust,
104 TSS_Deep_Finalize,
105 TSS_Deep_Initialize,
106 TSS_Composite_Equality,
df3e68b1 107 TSS_Finalize_Address,
6e40e481 108 TSS_From_Any,
fbf5a39b 109 TSS_Init_Proc,
cefce34c 110 TSS_CPP_Init_Proc,
fbf5a39b
AC
111 TSS_RAS_Access,
112 TSS_RAS_Dereference,
113 TSS_Rep_To_Pos,
26fd4eae 114 TSS_Slice_Assign,
fbf5a39b
AC
115 TSS_Stream_Input,
116 TSS_Stream_Output,
117 TSS_Stream_Read,
6e40e481
TQ
118 TSS_Stream_Write,
119 TSS_To_Any,
120 TSS_TypeCode);
fbf5a39b
AC
121
122 TSS_Null : constant TNT := " ";
123 -- Dummy entry used to indicated that this is not really a TSS
124
125 function Get_TSS_Name (E : Entity_Id) return TSS_Name_Type;
126 -- Given an entity, if it is a TSS, then return the corresponding TSS
127 -- name type, otherwise return TSS_Null.
128
129 function Make_TSS_Name
130 (Typ : Entity_Id;
131 Nam : TSS_Name_Type) return Name_Id;
132 -- Construct the name as described above for the given TSS routine
133 -- identified by Nam for the type identified by Typ.
134
135 function Make_TSS_Name_Local
136 (Typ : Entity_Id;
137 Nam : TSS_Name_Type) return Name_Id;
edd63e9b
ES
138 -- Similar to the above call, but a string of the form _nnn is inserted
139 -- before the TSS code suffix, where nnn is a unique serial number. This
140 -- is used when multiple instances of the same TSS routine may be
141 -- generated in the same scope (see also discussion above of current
142 -- limitations).
fbf5a39b
AC
143
144 function Make_Init_Proc_Name (Typ : Entity_Id) return Name_Id;
145 -- Version for init procs, same as Make_TSS_Name (Typ, TSS_Init_Proc)
146
cefce34c
JM
147 function Is_CPP_Init_Proc (E : Entity_Id) return Boolean;
148 -- Version for CPP init procs, same as Is_TSS (E, TSS_CPP_Init_Proc);
149
150 function Is_Init_Proc (E : Entity_Id) return Boolean;
151 -- Version for init procs, same as Is_TSS (E, TSS_Init_Proc);
152
c7732bbe
EB
153 -- WARNING: There is a matching C declaration of this subprogram in fe.h
154
fbf5a39b
AC
155 function Is_TSS (E : Entity_Id; Nam : TSS_Name_Type) return Boolean;
156 -- Determines if given entity (E) is the name of a TSS identified by Nam
157
158 function Is_TSS (N : Name_Id; Nam : TSS_Name_Type) return Boolean;
159 -- Same test applied directly to a Name_Id value
160
fbf5a39b
AC
161 -----------------------------------------
162 -- TSS Data structures and Subprograms --
163 -----------------------------------------
70482933
RK
164
165 -- The TSS's for a given type are stored in an element list associated with
166 -- the type, and referenced from the TSS_Elist field of the N_Freeze_Entity
167 -- node associated with the type (all types that need TSS's always need to
168 -- be explicitly frozen, so the N_Freeze_Entity node always exists).
169
fbf5a39b
AC
170 function TSS (Typ : Entity_Id; Nam : TSS_Name_Type) return Entity_Id;
171 -- Finds the TSS with the given name associated with the given type
172 -- If no such TSS exists, then Empty is returned;
173
70482933
RK
174 function TSS (Typ : Entity_Id; Nam : Name_Id) return Entity_Id;
175 -- Finds the TSS with the given name associated with the given type. If
176 -- no such TSS exists, then Empty is returned.
177
fbf5a39b
AC
178 function Same_TSS (E1, E2 : Entity_Id) return Boolean;
179 -- Returns True if E1 and E2 are the same kind of TSS, even if the names
180 -- are different (i.e. if the names of E1 and E2 end with two upper case
181 -- letters that are the same).
182
70482933
RK
183 procedure Set_TSS (Typ : Entity_Id; TSS : Entity_Id);
184 -- This procedure is used to install a newly created TSS. The second
b5ace3b7
AC
185 -- argument is the entity for such a new TSS. This entity is placed in the
186 -- TSS list for the type given as the first argument, replacing an old
187 -- entry of the same name if one was present. The tree for the body of this
188 -- TSS, which is not analyzed yet, is placed in the actions field of the
189 -- freeze node for the type. All such bodies are inserted into the main
190 -- tree and analyzed at the point at which the freeze node itself is
191 -- expanded.
70482933
RK
192
193 procedure Copy_TSS (TSS : Entity_Id; Typ : Entity_Id);
194 -- Given an existing TSS for another type (which is already installed,
195 -- analyzed and expanded), install it as the corresponding TSS for Typ.
b5ace3b7
AC
196 -- Note that this just copies a reference, not the tree. This can also be
197 -- used to initially install a TSS in the case where the subprogram for the
198 -- TSS has already been created and its declaration processed.
70482933 199
cefce34c
JM
200 function CPP_Init_Proc (Typ : Entity_Id) return Entity_Id;
201 -- Obtains the CPP_Init TSS entity the given type. The CPP_Init TSS is a
202 -- procedure used to initialize the C++ part of the primary and secondary
203 -- dispatch tables of a tagged type derived from CPP types.
204
236fecbf
JM
205 function Init_Proc
206 (Typ : Entity_Id;
207 Ref : Entity_Id := Empty) return Entity_Id;
70482933
RK
208 -- Obtains the _init TSS entry for the given type. This function call is
209 -- equivalent to TSS (Typ, Name_uInit). The _init TSS is the procedure
210 -- used to initialize otherwise uninitialized instances of a type. If
211 -- there is no _init TSS, then the type requires no initialization. Note
212 -- that subtypes and implicit types never have an _init TSS since subtype
213 -- objects are always initialized using the initialization procedure for
214 -- the corresponding base type (see Base_Init_Proc function). A special
215 -- case arises for concurrent types. Such types do not themselves have an
fbf5a39b 216 -- init proc TSS, but initialization is required. The init proc used is
236fecbf 217 -- the one for the corresponding record type (see Base_Init_Proc). If
7d9880c9 218 -- Ref is present it is a call to a subprogram whose profile matches the
236fecbf
JM
219 -- profile of the required constructor (this argument is used to handle
220 -- non-default CPP constructors).
70482933 221
236fecbf
JM
222 function Base_Init_Proc
223 (Typ : Entity_Id;
224 Ref : Entity_Id := Empty) return Entity_Id;
70482933
RK
225 -- Obtains the _Init TSS entry from the base type of the entity, and also
226 -- deals with going indirect through the Corresponding_Record_Type field
227 -- for concurrent objects (which are initialized with the initialization
236fecbf
JM
228 -- routine for the corresponding record type). Returns Empty if there is no
229 -- _Init TSS entry for the base type. If Ref is present it is a call to a
230 -- subprogram whose profile matches the profile of the required constructor
231 -- (this argument is used to handle non-default CPP constructors).
70482933
RK
232
233 procedure Set_Init_Proc (Typ : Entity_Id; Init : Entity_Id);
234 pragma Inline (Set_Init_Proc);
235 -- The second argument is the _init TSS to be established for the type
236 -- given as the first argument. Equivalent to Set_TSS (Typ, Init).
237
238 function Has_Non_Null_Base_Init_Proc (Typ : Entity_Id) return Boolean;
239 -- Returns true if the given type has a defined Base_Init_Proc and
240 -- this init proc is not a null init proc (null init procs occur as
db17411e 241 -- a result of the processing for Initialize_Scalars). This function
fbf5a39b
AC
242 -- is used to test for the presence of an init proc in cases where
243 -- a null init proc is considered equivalent to no init proc.
70482933 244
6e40e481
TQ
245 function Find_Inherited_TSS
246 (Typ : Entity_Id;
247 Nam : TSS_Name_Type) return Entity_Id;
248 -- Returns the TSS of name Nam of Typ, or of its closest ancestor defining
249 -- such a TSS. Empty is returned is neither Typ nor any of its ancestors
250 -- have such a TSS.
251
70482933 252end Exp_Tss;