1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- Type Support Subprogram (TSS) handling
29 with Types
; use Types
;
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
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.
48 -------------------------
49 -- Current Limitations --
50 -------------------------
52 -- In the current version of this package, only the case of generating a
53 -- TSS at the point of declaration of the type is accomodated. A clear
54 -- improvement would be to follow through with the full implementation
55 -- as described above, and also accomodate the requirement of generating
56 -- only one copy in a given object file.
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.
67 -- A TSS is identified by its Chars name. The name has the form typXY,
68 -- where typ is the type name, and XY are two characters that identify
69 -- the particular TSS routine, using the following codes:
71 -- Note: When making additions to this list, update the list in snames.adb
73 type TSS_Name_Type
is new String (1 .. 2);
74 subtype TNT
is TSS_Name_Type
;
76 TSS_Deep_Adjust
: constant TNT
:= "DA"; -- Deep Adjust
77 TSS_Deep_Finalize
: constant TNT
:= "DF"; -- Deep Finalize
78 TSS_Deep_Initialize
: constant TNT
:= "DI"; -- Deep Initialize
79 TSS_Composite_Equality
: constant TNT
:= "EQ"; -- Composite Equality
80 TSS_Init_Proc
: constant TNT
:= "IP"; -- Initialization Procedure
81 TSS_RAS_Access
: constant TNT
:= "RA"; -- RAs type access
82 TSS_RAS_Dereference
: constant TNT
:= "RD"; -- RAs type deference
83 TSS_Rep_To_Pos
: constant TNT
:= "RP"; -- Rep to Pos conversion
84 TSS_Slice_Assign
: constant TNT
:= "SA"; -- Slice assignment
85 TSS_Stream_Input
: constant TNT
:= "SI"; -- Stream Input attribute
86 TSS_Stream_Output
: constant TNT
:= "SO"; -- Stream Output attribute
87 TSS_Stream_Read
: constant TNT
:= "SR"; -- Stream Read attribute
88 TSS_Stream_Write
: constant TNT
:= "SW"; -- Stream Write attribute
90 OK_TSS_Names
: constant array (Natural range <>) of TSS_Name_Type
:=
94 TSS_Composite_Equality
,
105 TSS_Null
: constant TNT
:= " ";
106 -- Dummy entry used to indicated that this is not really a TSS
108 function Get_TSS_Name
(E
: Entity_Id
) return TSS_Name_Type
;
109 -- Given an entity, if it is a TSS, then return the corresponding TSS
110 -- name type, otherwise return TSS_Null.
112 function Make_TSS_Name
114 Nam
: TSS_Name_Type
) return Name_Id
;
115 -- Construct the name as described above for the given TSS routine
116 -- identified by Nam for the type identified by Typ.
118 function Make_TSS_Name_Local
120 Nam
: TSS_Name_Type
) return Name_Id
;
121 -- Similar to the above call, but a string of the form _nnn is appended
122 -- to the name, where nnn is a unique serial number. This is used when
123 -- multiple instances of the same TSS routine may be generated in the
124 -- same scope (see also discussion above of current limitations).
126 function Make_Init_Proc_Name
(Typ
: Entity_Id
) return Name_Id
;
127 -- Version for init procs, same as Make_TSS_Name (Typ, TSS_Init_Proc)
129 function Is_TSS
(E
: Entity_Id
; Nam
: TSS_Name_Type
) return Boolean;
130 -- Determines if given entity (E) is the name of a TSS identified by Nam
132 function Is_TSS
(N
: Name_Id
; Nam
: TSS_Name_Type
) return Boolean;
133 -- Same test applied directly to a Name_Id value
135 function Is_Init_Proc
(E
: Entity_Id
) return Boolean;
136 -- Version for init procs, same as Is_TSS (E, TSS_Init_Proc);
138 -----------------------------------------
139 -- TSS Data structures and Subprograms --
140 -----------------------------------------
142 -- The TSS's for a given type are stored in an element list associated with
143 -- the type, and referenced from the TSS_Elist field of the N_Freeze_Entity
144 -- node associated with the type (all types that need TSS's always need to
145 -- be explicitly frozen, so the N_Freeze_Entity node always exists).
147 function TSS
(Typ
: Entity_Id
; Nam
: TSS_Name_Type
) return Entity_Id
;
148 -- Finds the TSS with the given name associated with the given type
149 -- If no such TSS exists, then Empty is returned;
151 function TSS
(Typ
: Entity_Id
; Nam
: Name_Id
) return Entity_Id
;
152 -- Finds the TSS with the given name associated with the given type. If
153 -- no such TSS exists, then Empty is returned.
155 function Same_TSS
(E1
, E2
: Entity_Id
) return Boolean;
156 -- Returns True if E1 and E2 are the same kind of TSS, even if the names
157 -- are different (i.e. if the names of E1 and E2 end with two upper case
158 -- letters that are the same).
160 procedure Set_TSS
(Typ
: Entity_Id
; TSS
: Entity_Id
);
161 -- This procedure is used to install a newly created TSS. The second
162 -- argument is the entity for such a new TSS. This entity is placed in
163 -- the TSS list for the type given as the first argument, replacing an
164 -- old entry of the same name if one was present. The tree for the body
165 -- of this TSS, which is not analyzed yet, is placed in the actions field
166 -- of the freeze node for the type. All such bodies are inserted into the
167 -- main tree and analyzed at the point at which the freeze node itself is
170 procedure Copy_TSS
(TSS
: Entity_Id
; Typ
: Entity_Id
);
171 -- Given an existing TSS for another type (which is already installed,
172 -- analyzed and expanded), install it as the corresponding TSS for Typ.
173 -- Note that this just copies a reference, not the tree. This can also
174 -- be used to initially install a TSS in the case where the subprogram
175 -- for the TSS has already been created and its declaration processed.
177 function Init_Proc
(Typ
: Entity_Id
) return Entity_Id
;
178 pragma Inline
(Init_Proc
);
179 -- Obtains the _init TSS entry for the given type. This function call is
180 -- equivalent to TSS (Typ, Name_uInit). The _init TSS is the procedure
181 -- used to initialize otherwise uninitialized instances of a type. If
182 -- there is no _init TSS, then the type requires no initialization. Note
183 -- that subtypes and implicit types never have an _init TSS since subtype
184 -- objects are always initialized using the initialization procedure for
185 -- the corresponding base type (see Base_Init_Proc function). A special
186 -- case arises for concurrent types. Such types do not themselves have an
187 -- init proc TSS, but initialization is required. The init proc used is
188 -- the one fot the corresponding record type (see Base_Init_Proc).
190 function Base_Init_Proc
(Typ
: Entity_Id
) return Entity_Id
;
191 -- Obtains the _Init TSS entry from the base type of the entity, and also
192 -- deals with going indirect through the Corresponding_Record_Type field
193 -- for concurrent objects (which are initialized with the initialization
194 -- routine for the corresponding record type). Returns Empty if there is
195 -- no _Init TSS entry for the base type.
197 procedure Set_Init_Proc
(Typ
: Entity_Id
; Init
: Entity_Id
);
198 pragma Inline
(Set_Init_Proc
);
199 -- The second argument is the _init TSS to be established for the type
200 -- given as the first argument. Equivalent to Set_TSS (Typ, Init).
202 function Has_Non_Null_Base_Init_Proc
(Typ
: Entity_Id
) return Boolean;
203 -- Returns true if the given type has a defined Base_Init_Proc and
204 -- this init proc is not a null init proc (null init procs occur as
205 -- a result of the processing for Initialize_Scalars. This function
206 -- is used to test for the presence of an init proc in cases where
207 -- a null init proc is considered equivalent to no init proc.