1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 -- This package contains routines involved in tagged types and dynamic
28 -- dispatching expansion.
30 with Types; use Types;
33 -- Number of predefined primitive operations added by the Expander
34 -- for a tagged type. If more predefined primitive operations are
35 -- added, the following items must be changed:
37 -- Ada.Tags.Defailt_Prim_Op_Count - indirect use
38 -- Exp_Disp.Default_Prim_Op_Position - indirect use
39 -- Exp_Disp.Set_All_DT_Position - direct use
41 Default_Prim_Op_Count : constant Int := 14;
43 type DT_Access_Action is
54 Get_Remotely_Callable,
57 Register_Interface_Tag,
66 Set_Remotely_Callable,
71 procedure Expand_Dispatching_Call (Call_Node : Node_Id);
72 -- Expand the call to the operation through the dispatch table and perform
73 -- the required tag checks when appropriate. For CPP types the call is
74 -- done through the Vtable (tag checks are not relevant)
76 procedure Expand_Interface_Actuals (Call_Node : Node_Id);
77 -- Ada 2005 (AI-251): Displace all the actuals corresponding to class-wide
78 -- interfaces to reference the interface tag of the actual object
80 procedure Expand_Interface_Conversion (N : Node_Id);
81 -- Ada 2005 (AI-251): N is a type-conversion node. Reference the base of
82 -- the object to give access to the interface tag associated with the
83 -- secondary dispatch table
85 function Expand_Interface_Thunk
87 Thunk_Alias : Node_Id;
89 Thunk_Tag : Entity_Id) return Node_Id;
90 -- Ada 2005 (AI-251): When a tagged type implements abstract interfaces we
91 -- generate additional subprograms (thunks) to have a layout compatible
92 -- with the C++ ABI. The thunk modifies the value of the first actual of
93 -- the call (that is, the pointer to the object) before transferring
94 -- control to the target function.
96 function Fill_DT_Entry
98 Prim : Entity_Id) return Node_Id;
99 -- Generate the code necessary to fill the appropriate entry of the
100 -- dispatch table of Prim's controlling type with Prim's address.
102 function Fill_Secondary_DT_Entry
105 Thunk_Id : Entity_Id;
106 Iface_DT_Ptr : Entity_Id) return Node_Id;
107 -- (Ada 2005): Generate the code necessary to fill the appropriate entry of
108 -- the secondary dispatch table of Prim's controlling type with Thunk_Id's
111 function Get_Remotely_Callable (Obj : Node_Id) return Node_Id;
112 -- Return an expression that holds True if the object can be transmitted
113 -- onto another partition according to E.4 (18)
115 function Init_Predefined_Interface_Primitives
116 (Typ : Entity_Id) return List_Id;
117 -- Ada 2005 (AI-251): Initialize the entries associated with predefined
118 -- primitives in all the secondary dispatch tables of Typ.
120 procedure Make_Abstract_Interface_DT
122 Acc_Disp_Tables : in out Elist_Id;
123 Result : out List_Id);
124 -- Ada 2005 (AI-251): Expand the declarations for the secondary Dispatch
125 -- Tables corresponding with an abstract interface. The reference to the
126 -- dispatch table is appended at the end of Acc_Disp_Tables; it will be
127 -- are later used to generate the corresponding initialization statement
128 -- (see Exp_Ch3.Build_Init_Procedure).
130 function Make_DT_Access_Action
132 Action : DT_Access_Action;
133 Args : List_Id) return Node_Id;
134 -- Generate a call to one of the Dispatch Table Access Subprograms defined
135 -- in Ada.Tags or in Interfaces.Cpp
137 function Make_DT (Typ : Entity_Id) return List_Id;
138 -- Expand the declarations for the Dispatch Table (or the Vtable in
139 -- the case of type whose ancestor is a CPP_Class)
141 function Make_Disp_Asynchronous_Select_Body
142 (Typ : Entity_Id) return Node_Id;
143 -- Ada 2005 (AI-345): Generate the body of the primitive operation of type
144 -- Typ used for dispatching in asynchronous selects.
146 function Make_Disp_Asynchronous_Select_Spec
147 (Typ : Entity_Id) return Node_Id;
148 -- Ada 2005 (AI-345): Generate the specification of the primitive operation
149 -- of type Typ used for dispatching in asynchronous selects.
151 function Make_Disp_Conditional_Select_Body
152 (Typ : Entity_Id) return Node_Id;
153 -- Ada 2005 (AI-345): Generate the body of the primitive operation of type
154 -- Typ used for dispatching in conditional selects.
156 function Make_Disp_Conditional_Select_Spec
157 (Typ : Entity_Id) return Node_Id;
158 -- Ada 2005 (AI-345): Generate the specification of the primitive operation
159 -- of type Typ used for dispatching in conditional selects.
161 function Make_Disp_Get_Prim_Op_Kind_Body
162 (Typ : Entity_Id) return Node_Id;
163 -- Ada 2005 (AI-345): Generate the body of the primitive operation of type
164 -- Typ used for retrieving the callable entity kind during dispatching in
165 -- asynchronous selects.
167 function Make_Disp_Get_Prim_Op_Kind_Spec
168 (Typ : Entity_Id) return Node_Id;
169 -- Ada 2005 (AI-345): Generate the specification of the primitive operation
170 -- of the type Typ use for retrieving the callable entity kind during
171 -- dispatching in asynchronous selects.
173 function Make_Disp_Select_Tables
174 (Typ : Entity_Id) return List_Id;
175 -- Ada 2005 (AI-345): Populate the two auxiliary tables in the TSD of Typ
176 -- used for dispatching in asynchronous, conditional and timed selects.
177 -- Generate code to set the primitive operation kinds and entry indices
178 -- of primitive operations and primitive wrappers.
180 function Make_Disp_Timed_Select_Body
181 (Typ : Entity_Id) return Node_Id;
182 -- Ada 2005 (AI-345): Generate the body of the primitive operation of type
183 -- Typ used for dispatching in timed selects.
185 function Make_Disp_Timed_Select_Spec
186 (Typ : Entity_Id) return Node_Id;
187 -- Ada 2005 (AI-345): Generate the specification of the primitive operation
188 -- of type Typ used for dispatching in timed selects.
190 procedure Set_All_DT_Position (Typ : Entity_Id);
191 -- Set the DT_Position field for each primitive operation. In the CPP
192 -- Class case check that no pragma CPP_Virtual is missing and that the
193 -- DT_Position are coherent
195 procedure Set_Default_Constructor (Typ : Entity_Id);
196 -- Typ is a CPP_Class type. Create the Init procedure of that type to
197 -- be the default constructor (i.e. the function returning this type,
198 -- having a pragma CPP_Constructor and no parameter)
200 procedure Write_DT (Typ : Entity_Id);
201 pragma Export (Ada, Write_DT);
202 -- Debugging procedure (to be called within gdb)