Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / i-cpp.ads
blobdf39bdb4df0bad8c18fb3c5098923c703e8ab3c2
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . C P P --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
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- --
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. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- Definitions for interfacing to C++ classes
36 -- This package corresponds to Ada.Tags but applied to tagged types which are
37 -- are imported from C++ and correspond exactly to a C++ Class. The code that
38 -- the GNAT front end generates does not know about the structure of the C++
39 -- dispatch table (Vtable) but always accesses it through the procedural
40 -- interface defined in this package, thus the implementation of this package
41 -- (the body) can be customized to another C++ compiler without any change in
42 -- the compiler code itself as long as this procedural interface is respected.
43 -- Note that Ada.Tags defines a very similar procedural interface to the
44 -- regular Ada Dispatch Table.
46 with System;
47 with System.Storage_Elements;
48 with Unchecked_Conversion;
50 package Interfaces.CPP is
52 type Vtable_Ptr is private;
54 function Expanded_Name (T : Vtable_Ptr) return String;
55 function External_Tag (T : Vtable_Ptr) return String;
57 private
58 package S renames System;
59 package SSE renames System.Storage_Elements;
61 type Vtable;
62 type Vtable_Ptr is access all Vtable;
64 type Type_Specific_Data;
65 type Type_Specific_Data_Ptr is access all Type_Specific_Data;
67 -- These subprograms are in the private part. They are never accessed
68 -- directly except from compiler generated code, which has access to
69 -- private components of packages via the Rtsfind interface.
71 procedure CPP_Set_Prim_Op_Address
72 (T : Vtable_Ptr;
73 Position : Positive;
74 Value : S.Address);
75 -- Given a pointer to a dispatch Table (T) and a position in the
76 -- dispatch Table put the address of the virtual function in it
77 -- (used for overriding)
79 function CPP_Get_Prim_Op_Address
80 (T : Vtable_Ptr;
81 Position : Positive)
82 return S.Address;
83 -- Given a pointer to a dispatch Table (T) and a position in the DT
84 -- this function returns the address of the virtual function stored
85 -- in it (used for dispatching calls)
87 procedure CPP_Set_Inheritance_Depth
88 (T : Vtable_Ptr;
89 Value : Natural);
90 -- Given a pointer to a dispatch Table, stores the value representing
91 -- the depth in the inheritance tree. Used during elaboration of the
92 -- tagged type.
94 function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural;
95 -- Given a pointer to a dispatch Table, retreives the value representing
96 -- the depth in the inheritance tree. Used for membership.
98 procedure CPP_Set_TSD (T : Vtable_Ptr; Value : S.Address);
99 -- Given a pointer T to a dispatch Table, stores the address of the
100 -- record containing the Type Specific Data generated by GNAT
102 function CPP_Get_TSD (T : Vtable_Ptr) return S.Address;
103 -- Given a pointer T to a dispatch Table, retreives the address of the
104 -- record containing the Type Specific Data generated by GNAT
106 CPP_DT_Prologue_Size : constant SSE.Storage_Count :=
107 SSE.Storage_Count
108 (2 * (Standard'Address_Size / S.Storage_Unit));
109 -- Size of the first part of the dispatch table
111 CPP_DT_Typeinfo_Ptr_Size : constant SSE.Storage_Count :=
112 SSE.Storage_Count
113 (Standard'Address_Size / System.Storage_Unit);
114 -- Size of the Typeinfo_Ptr field of the Dispatch Table.
116 CPP_DT_Entry_Size : constant SSE.Storage_Count :=
117 SSE.Storage_Count
118 (1 * (Standard'Address_Size / S.Storage_Unit));
119 -- Size of each primitive operation entry in the Dispatch Table.
121 CPP_TSD_Prologue_Size : constant SSE.Storage_Count :=
122 SSE.Storage_Count
123 (4 * (Standard'Address_Size / S.Storage_Unit));
124 -- Size of the first part of the type specific data
126 CPP_TSD_Entry_Size : constant SSE.Storage_Count :=
127 SSE.Storage_Count
128 (1 * (Standard'Address_Size / S.Storage_Unit));
129 -- Size of each ancestor tag entry in the TSD
131 procedure CPP_Inherit_DT
132 (Old_T : Vtable_Ptr;
133 New_T : Vtable_Ptr;
134 Entry_Count : Natural);
135 -- Entry point used to initialize the DT of a type knowing the
136 -- tag of the direct ancestor and the number of primitive ops that are
137 -- inherited (Entry_Count).
139 procedure CPP_Inherit_TSD
140 (Old_TSD : S.Address;
141 New_Tag : Vtable_Ptr);
142 -- Entry point used to initialize the TSD of a type knowing the
143 -- TSD of the direct ancestor.
145 function CPP_CW_Membership (Obj_Tag, Typ_Tag : Vtable_Ptr) return Boolean;
146 -- Given the tag of an object and the tag associated to a type, return
147 -- true if Obj is in Typ'Class.
149 procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : S.Address);
150 -- Set the address of the string containing the external tag
151 -- in the Dispatch table
153 function CPP_Get_External_Tag (T : Vtable_Ptr) return S.Address;
154 -- Retrieve the address of a null terminated string containing
155 -- the external name
157 procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : S.Address);
158 -- Set the address of the string containing the expanded name
159 -- in the Dispatch table
161 function CPP_Get_Expanded_Name (T : Vtable_Ptr) return S.Address;
162 -- Retrieve the address of a null terminated string containing
163 -- the expanded name
165 procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean);
166 -- Since the notions of spec/body distinction and categorized packages
167 -- do not exist in C, this procedure will do nothing
169 function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean;
170 -- This function will always return True for the reason explained above
172 procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset);
173 -- Sets the Offset of the implicit record controller when the object
174 -- has controlled components. Set to O otherwise.
176 function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset;
177 -- Return the Offset of the implicit record controller when the object
178 -- has controlled components. O otherwise.
180 function Displaced_This
181 (Current_This : S.Address;
182 Vptr : Vtable_Ptr;
183 Position : Positive)
184 return S.Address;
185 -- Compute the displacement on the "this" pointer in order to be
186 -- compatible with MI.
187 -- (used for virtual function calls)
189 function TSD (T : Vtable_Ptr) return Type_Specific_Data_Ptr;
190 -- This function is conceptually equivalent to Get_TSD, but
191 -- returning a Type_Specific_Data_Ptr type (rather than an Address)
192 -- simplifies the implementation of the other subprograms.
194 type Addr_Ptr is access System.Address;
196 function To_Address is
197 new Unchecked_Conversion (Vtable_Ptr, System.Address);
199 function To_Addr_Ptr is
200 new Unchecked_Conversion (System.Address, Addr_Ptr);
202 function To_Type_Specific_Data_Ptr is
203 new Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
205 pragma Inline (CPP_Set_Prim_Op_Address);
206 pragma Inline (CPP_Get_Prim_Op_Address);
207 pragma Inline (CPP_Set_Inheritance_Depth);
208 pragma Inline (CPP_Get_Inheritance_Depth);
209 pragma Inline (CPP_Set_TSD);
210 pragma Inline (CPP_Get_TSD);
211 pragma Inline (CPP_Inherit_DT);
212 pragma Inline (CPP_CW_Membership);
213 pragma Inline (CPP_Set_External_Tag);
214 pragma Inline (CPP_Get_External_Tag);
215 pragma Inline (CPP_Set_Expanded_Name);
216 pragma Inline (CPP_Get_Expanded_Name);
217 pragma Inline (CPP_Set_Remotely_Callable);
218 pragma Inline (CPP_Get_Remotely_Callable);
219 pragma Inline (Displaced_This);
220 pragma Inline (TSD);
222 end Interfaces.CPP;