aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/i-cpp.adb
blob: 24015f10d0b999a9116deb2c4903314349fd1731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT RUN-TIME COMPONENTS                         --
--                                                                          --
--                       I N T E R F A C E S . C P P                        --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--          Copyright (C) 1992-2004, Free Software Foundation, Inc.         --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
-- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
-- MA 02111-1307, USA.                                                      --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

with Ada.Tags;                use Ada.Tags;
with System;                  use System;
with System.Storage_Elements; use System.Storage_Elements;
with Unchecked_Conversion;

package body Interfaces.CPP is

   --  The declarations below need (extensive) comments ???

   subtype Cstring is String (Positive);
   type Cstring_Ptr is access all Cstring;
   type Tag_Table is array (Natural range <>) of Vtable_Ptr;
   pragma Suppress_Initialization (Tag_Table);

   type Type_Specific_Data is record
      Idepth        : Natural;
      Expanded_Name : Cstring_Ptr;
      External_Tag  : Cstring_Ptr;
      HT_Link       : Tag;
      Ancestor_Tags : Tag_Table (Natural);
   end record;

   type Vtable_Entry is record
     Pfn : System.Address;
   end record;

   type Type_Specific_Data_Ptr is access all Type_Specific_Data;
   type Vtable_Entry_Array is array (Positive range <>) of Vtable_Entry;

   type VTable is record
      Prims_Ptr : Vtable_Entry_Array (Positive);
      TSD       : Type_Specific_Data_Ptr;
   end record;

   --------------------------------------------------------
   -- Unchecked Conversions for Tag, Vtable_Ptr, and TSD --
   --------------------------------------------------------

   function To_Type_Specific_Data_Ptr is
     new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);

   function To_Address is
     new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);

   ---------------------------------------------
   -- Unchecked Conversions for String Fields --
   ---------------------------------------------

   function To_Cstring_Ptr is
     new Unchecked_Conversion (Address, Cstring_Ptr);

   function To_Address is
     new Unchecked_Conversion (Cstring_Ptr, Address);

   -----------------------
   -- Local Subprograms --
   -----------------------

   function Length (Str : Cstring_Ptr) return Natural;
   --  Length of string represented by the given pointer (treating the
   --  string as a C-style string, which is Nul terminated).

   -----------------------
   -- CPP_CW_Membership --
   -----------------------

   function CPP_CW_Membership
     (Obj_Tag : Vtable_Ptr;
      Typ_Tag : Vtable_Ptr) return Boolean
   is
      Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
   begin
      return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
   end CPP_CW_Membership;

   ---------------------------
   -- CPP_Get_Expanded_Name --
   ---------------------------

   function CPP_Get_Expanded_Name (T : Vtable_Ptr) return Address is
   begin
      return To_Address (T.TSD.Expanded_Name);
   end CPP_Get_Expanded_Name;

   --------------------------
   -- CPP_Get_External_Tag --
   --------------------------

   function CPP_Get_External_Tag (T : Vtable_Ptr) return Address is
   begin
      return To_Address (T.TSD.External_Tag);
   end CPP_Get_External_Tag;

   -------------------------------
   -- CPP_Get_Inheritance_Depth --
   -------------------------------

   function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural is
   begin
      return T.TSD.Idepth;
   end CPP_Get_Inheritance_Depth;

   -------------------------
   -- CPP_Get_Prim_Op_Address --
   -------------------------

   function CPP_Get_Prim_Op_Address
     (T        : Vtable_Ptr;
      Position : Positive) return Address
   is
   begin
      return T.Prims_Ptr (Position).Pfn;
   end CPP_Get_Prim_Op_Address;

   -----------------------
   -- CPP_Get_RC_Offset --
   -----------------------

   function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset is
      pragma Warnings (Off, T);
   begin
      return 0;
   end CPP_Get_RC_Offset;

   -------------------------------
   -- CPP_Get_Remotely_Callable --
   -------------------------------

   function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean is
      pragma Warnings (Off, T);
   begin
      return True;
   end CPP_Get_Remotely_Callable;

   -----------------
   -- CPP_Get_TSD --
   -----------------

   function CPP_Get_TSD  (T : Vtable_Ptr) return Address is
   begin
      return To_Address (T.TSD);
   end CPP_Get_TSD;

   --------------------
   -- CPP_Inherit_DT --
   --------------------

   procedure CPP_Inherit_DT
    (Old_T   : Vtable_Ptr;
     New_T   : Vtable_Ptr;
     Entry_Count : Natural)
   is
   begin
      if Old_T /= null then
         New_T.Prims_Ptr (1 .. Entry_Count)
           := Old_T.Prims_Ptr (1 .. Entry_Count);
      end if;
   end CPP_Inherit_DT;

   ---------------------
   -- CPP_Inherit_TSD --
   ---------------------

   procedure CPP_Inherit_TSD
     (Old_TSD : Address;
      New_Tag : Vtable_Ptr)
   is
      TSD : constant Type_Specific_Data_Ptr :=
              To_Type_Specific_Data_Ptr (Old_TSD);

      New_TSD : Type_Specific_Data renames New_Tag.TSD.all;

   begin
      if TSD /= null then
         New_TSD.Idepth := TSD.Idepth + 1;
         New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
           := TSD.Ancestor_Tags (0 .. TSD.Idepth);
      else
         New_TSD.Idepth := 0;
      end if;

      New_TSD.Ancestor_Tags (0) := New_Tag;
   end CPP_Inherit_TSD;

   ---------------------------
   -- CPP_Set_Expanded_Name --
   ---------------------------

   procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : Address) is
   begin
      T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
   end CPP_Set_Expanded_Name;

   --------------------------
   -- CPP_Set_External_Tag --
   --------------------------

   procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : Address) is
   begin
      T.TSD.External_Tag := To_Cstring_Ptr (Value);
   end CPP_Set_External_Tag;

   -------------------------------
   -- CPP_Set_Inheritance_Depth --
   -------------------------------

   procedure CPP_Set_Inheritance_Depth
     (T     : Vtable_Ptr;
      Value : Natural)
   is
   begin
      T.TSD.Idepth := Value;
   end CPP_Set_Inheritance_Depth;

   -----------------------------
   -- CPP_Set_Prim_Op_Address --
   -----------------------------

   procedure CPP_Set_Prim_Op_Address
     (T        : Vtable_Ptr;
      Position : Positive;
      Value    : Address)
   is
   begin
      T.Prims_Ptr (Position).Pfn := Value;
   end CPP_Set_Prim_Op_Address;

   -----------------------
   -- CPP_Set_RC_Offset --
   -----------------------

   procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset) is
      pragma Warnings (Off, T);
      pragma Warnings (Off, Value);
   begin
      null;
   end CPP_Set_RC_Offset;

   -------------------------------
   -- CPP_Set_Remotely_Callable --
   -------------------------------

   procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean) is
      pragma Warnings (Off, T);
      pragma Warnings (Off, Value);
   begin
      null;
   end CPP_Set_Remotely_Callable;

   -----------------
   -- CPP_Set_TSD --
   -----------------

   procedure CPP_Set_TSD (T : Vtable_Ptr; Value : Address) is
   begin
      T.TSD := To_Type_Specific_Data_Ptr (Value);
   end CPP_Set_TSD;

   --------------------
   -- Displaced_This --
   --------------------

   function Displaced_This
    (Current_This : System.Address;
     Vptr         : Vtable_Ptr;
     Position     : Positive)
     return         System.Address
   is
      pragma Warnings (Off, Vptr);
      pragma Warnings (Off, Position);

   begin
      return Current_This;

      --  why is the following here commented out ???
      --  + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
   end Displaced_This;

   -------------------
   -- Expanded_Name --
   -------------------

   function Expanded_Name (T : Vtable_Ptr) return String is
      Result : constant Cstring_Ptr := T.TSD.Expanded_Name;
   begin
      return Result (1 .. Length (Result));
   end Expanded_Name;

   ------------------
   -- External_Tag --
   ------------------

   function External_Tag (T : Vtable_Ptr) return String is
      Result : constant Cstring_Ptr := T.TSD.External_Tag;
   begin
      return Result (1 .. Length (Result));
   end External_Tag;

   ------------
   -- Length --
   ------------

   function Length (Str : Cstring_Ptr) return Natural is
      Len : Integer := 1;

   begin
      while Str (Len) /= ASCII.Nul loop
         Len := Len + 1;
      end loop;

      return Len - 1;
   end Length;

end Interfaces.CPP;