OSDN Git Service

2005-03-29 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / i-cpp.ads
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 ------------------------------------------------------------------------------
33
34 --  Definitions for interfacing to C++ classes
35
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.
45
46 with System;
47 with System.Storage_Elements;
48 with Unchecked_Conversion;
49
50 package Interfaces.CPP is
51
52    type Vtable_Ptr is private;
53
54    function Expanded_Name (T : Vtable_Ptr) return String;
55    function External_Tag  (T : Vtable_Ptr) return String;
56
57 private
58    package S   renames System;
59    package SSE renames System.Storage_Elements;
60
61    type Vtable;
62    type Vtable_Ptr is access all Vtable;
63
64    type Type_Specific_Data;
65    type Type_Specific_Data_Ptr is access all Type_Specific_Data;
66
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.
70
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)
78
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)
86
87    procedure CPP_Set_TSD (T : Vtable_Ptr; Value : S.Address);
88    --  Given a pointer T to a dispatch Table, stores the address of the
89    --  record containing the Type Specific Data generated by GNAT
90
91    CPP_DT_Prologue_Size : constant SSE.Storage_Count :=
92                             SSE.Storage_Count
93                               (2 * (Standard'Address_Size / S.Storage_Unit));
94    --  Size of the first part of the dispatch table
95
96    CPP_DT_Typeinfo_Ptr_Size : constant SSE.Storage_Count :=
97                             SSE.Storage_Count
98                               (Standard'Address_Size / System.Storage_Unit);
99    --  Size of the Typeinfo_Ptr field of the Dispatch Table.
100
101    CPP_DT_Entry_Size : constant SSE.Storage_Count :=
102                          SSE.Storage_Count
103                            (1 * (Standard'Address_Size / S.Storage_Unit));
104    --  Size of each primitive operation entry in the Dispatch Table.
105
106    CPP_TSD_Prologue_Size : constant SSE.Storage_Count :=
107                              SSE.Storage_Count
108                                (4 * (Standard'Address_Size / S.Storage_Unit));
109    --  Size of the first part of the type specific data
110
111    CPP_TSD_Entry_Size : constant SSE.Storage_Count :=
112                           SSE.Storage_Count
113                             (1 * (Standard'Address_Size / S.Storage_Unit));
114    --  Size of each ancestor tag entry in the TSD
115
116    procedure CPP_Inherit_DT
117     (Old_T       : Vtable_Ptr;
118      New_T       : Vtable_Ptr;
119      Entry_Count : Natural);
120    --  Entry point used to initialize the DT of a type knowing the
121    --  tag of the direct ancestor and the number of primitive ops that are
122    --  inherited (Entry_Count).
123
124    procedure CPP_Inherit_TSD
125      (Old_Tag : Vtable_Ptr;
126       New_Tag : Vtable_Ptr);
127    --  Entry point used to initialize the TSD of a type knowing the
128    --  TSD of the direct ancestor.
129
130    function CPP_CW_Membership (Obj_Tag, Typ_Tag : Vtable_Ptr) return Boolean;
131    --  Given the tag of an object and the tag associated to a type, return
132    --  true if Obj is in Typ'Class.
133
134    procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : S.Address);
135    --  Set the address of the string containing the external tag
136    --  in the Dispatch table
137
138    function CPP_Get_External_Tag (T : Vtable_Ptr) return S.Address;
139    --  Retrieve the address of a null terminated string containing
140    --  the external name
141
142    procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : S.Address);
143    --  Set the address of the string containing the expanded name
144    --  in the Dispatch table
145
146    procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean);
147    --  Since the notions of spec/body distinction and categorized packages
148    --  do not exist in C, this procedure will do nothing
149
150    function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean;
151    --  This function will always return True for the reason explained above
152
153    procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset);
154    --  Sets the Offset of the implicit record controller when the object
155    --  has controlled components. Set to O otherwise.
156
157    function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset;
158    --  Return the Offset of the implicit record controller when the object
159    --  has controlled components. O otherwise.
160
161    function Displaced_This
162     (Current_This : S.Address;
163      Vptr         : Vtable_Ptr;
164      Position     : Positive)
165      return         S.Address;
166    --  Compute the displacement on the "this" pointer in order to be
167    --  compatible with MI.
168    --  (used for virtual function calls)
169
170    function TSD (T : Vtable_Ptr) return Type_Specific_Data_Ptr;
171    --  Given a pointer T to a dispatch Table, retreives the address of the
172    --  record containing the Type Specific Data generated by GNAT
173
174    type Addr_Ptr is access System.Address;
175
176    function To_Address is
177      new Unchecked_Conversion (Vtable_Ptr, System.Address);
178
179    function To_Addr_Ptr is
180       new Unchecked_Conversion (System.Address, Addr_Ptr);
181
182    function To_Type_Specific_Data_Ptr is
183      new Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
184
185    pragma Inline (CPP_Set_Prim_Op_Address);
186    pragma Inline (CPP_Get_Prim_Op_Address);
187    pragma Inline (CPP_Set_TSD);
188    pragma Inline (CPP_Inherit_DT);
189    pragma Inline (CPP_CW_Membership);
190    pragma Inline (CPP_Set_External_Tag);
191    pragma Inline (CPP_Get_External_Tag);
192    pragma Inline (CPP_Set_Expanded_Name);
193    pragma Inline (CPP_Set_Remotely_Callable);
194    pragma Inline (CPP_Get_Remotely_Callable);
195    pragma Inline (Displaced_This);
196    pragma Inline (TSD);
197
198 end Interfaces.CPP;