FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / i-cpp.ads
blobfa6535d09c9196897556b79068e236e0099a2fdb
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 -- --
10 -- Copyright (C) 1992-2000, Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- Definitions for interfacing to C++ classes
37 with System;
38 with System.Storage_Elements;
40 package Interfaces.CPP is
42 package S renames System;
43 package SSE renames System.Storage_Elements;
45 -- This package corresponds to Ada.Tags but applied to tagged types
46 -- which are 'imported' from C++ and correspond to exactly to a C++
47 -- Class. GNAT doesn't know about the structure od the C++ dispatch
48 -- table (Vtable) but always access it through the procedural interface
49 -- defined below, thus the implementation of this package (the body) can
50 -- be customized to another C++ compiler without any change in the
51 -- compiler code itself as long as this procedural interface is
52 -- respected. Note that Ada.Tags defines a very similar procedural
53 -- interface to the regular Ada Dispatch Table.
55 type Vtable_Ptr is private;
57 function Expanded_Name (T : Vtable_Ptr) return String;
58 function External_Tag (T : Vtable_Ptr) return String;
60 private
62 procedure CPP_Set_Prim_Op_Address
63 (T : Vtable_Ptr;
64 Position : Positive;
65 Value : S.Address);
66 -- Given a pointer to a dispatch Table (T) and a position in the
67 -- dispatch Table put the address of the virtual function in it
68 -- (used for overriding)
70 function CPP_Get_Prim_Op_Address
71 (T : Vtable_Ptr;
72 Position : Positive)
73 return S.Address;
74 -- Given a pointer to a dispatch Table (T) and a position in the DT
75 -- this function returns the address of the virtual function stored
76 -- in it (used for dispatching calls)
78 procedure CPP_Set_Inheritance_Depth
79 (T : Vtable_Ptr;
80 Value : Natural);
81 -- Given a pointer to a dispatch Table, stores the value representing
82 -- the depth in the inheritance tree. Used during elaboration of the
83 -- tagged type.
85 function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural;
86 -- Given a pointer to a dispatch Table, retreives the value representing
87 -- the depth in the inheritance tree. Used for membership.
89 procedure CPP_Set_TSD (T : Vtable_Ptr; Value : S.Address);
90 -- Given a pointer T to a dispatch Table, stores the address of the
91 -- record containing the Type Specific Data generated by GNAT
93 function CPP_Get_TSD (T : Vtable_Ptr) return S.Address;
94 -- Given a pointer T to a dispatch Table, retreives the address of the
95 -- record containing the Type Specific Data generated by GNAT
97 CPP_DT_Prologue_Size : constant SSE.Storage_Count :=
98 SSE.Storage_Count
99 (2 * (Standard'Address_Size / S.Storage_Unit));
100 -- Size of the first part of the dispatch table
102 CPP_DT_Entry_Size : constant SSE.Storage_Count :=
103 SSE.Storage_Count
104 (1 * (Standard'Address_Size / S.Storage_Unit));
105 -- Size of each primitive operation entry in the Dispatch Table.
107 CPP_TSD_Prologue_Size : constant SSE.Storage_Count :=
108 SSE.Storage_Count
109 (4 * (Standard'Address_Size / S.Storage_Unit));
110 -- Size of the first part of the type specific data
112 CPP_TSD_Entry_Size : constant SSE.Storage_Count :=
113 SSE.Storage_Count
114 (Standard'Address_Size / S.Storage_Unit);
115 -- Size of each ancestor tag entry in the TSD
117 procedure CPP_Inherit_DT
118 (Old_T : Vtable_Ptr;
119 New_T : Vtable_Ptr;
120 Entry_Count : Natural);
121 -- Entry point used to initialize the DT of a type knowing the
122 -- tag of the direct ancestor and the number of primitive ops that are
123 -- inherited (Entry_Count).
125 procedure CPP_Inherit_TSD
126 (Old_TSD : S.Address;
127 New_Tag : Vtable_Ptr);
128 -- Entry point used to initialize the TSD of a type knowing the
129 -- TSD of the direct ancestor.
131 function CPP_CW_Membership (Obj_Tag, Typ_Tag : Vtable_Ptr) return Boolean;
132 -- Given the tag of an object and the tag associated to a type, return
133 -- true if Obj is in Typ'Class.
135 procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : S.Address);
136 -- Set the address of the string containing the external tag
137 -- in the Dispatch table
139 function CPP_Get_External_Tag (T : Vtable_Ptr) return S.Address;
140 -- Retrieve the address of a null terminated string containing
141 -- the external name
143 procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : S.Address);
144 -- Set the address of the string containing the expanded name
145 -- in the Dispatch table
147 function CPP_Get_Expanded_Name (T : Vtable_Ptr) return S.Address;
148 -- Retrieve the address of a null terminated string containing
149 -- the expanded name
151 procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean);
152 -- Since the notions of spec/body distinction and categorized packages
153 -- do not exist in C, this procedure will do nothing
155 function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean;
156 -- This function will always return True for the reason explained above
158 procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset);
159 -- Sets the Offset of the implicit record controller when the object
160 -- has controlled components. Set to O otherwise.
162 function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset;
163 -- Return the Offset of the implicit record controller when the object
164 -- has controlled components. O otherwise.
166 function Displaced_This
167 (Current_This : S.Address;
168 Vptr : Vtable_Ptr;
169 Position : Positive)
170 return S.Address;
171 -- Compute the displacement on the "this" pointer in order to be
172 -- compatible with MI.
173 -- (used for virtual function calls)
175 type Vtable;
176 type Vtable_Ptr is access all Vtable;
178 pragma Inline (CPP_Set_Prim_Op_Address);
179 pragma Inline (CPP_Get_Prim_Op_Address);
180 pragma Inline (CPP_Set_Inheritance_Depth);
181 pragma Inline (CPP_Get_Inheritance_Depth);
182 pragma Inline (CPP_Set_TSD);
183 pragma Inline (CPP_Get_TSD);
184 pragma Inline (CPP_Inherit_DT);
185 pragma Inline (CPP_CW_Membership);
186 pragma Inline (CPP_Set_External_Tag);
187 pragma Inline (CPP_Get_External_Tag);
188 pragma Inline (CPP_Set_Expanded_Name);
189 pragma Inline (CPP_Get_Expanded_Name);
190 pragma Inline (CPP_Set_Remotely_Callable);
191 pragma Inline (CPP_Get_Remotely_Callable);
192 pragma Inline (Displaced_This);
194 end Interfaces.CPP;