OSDN Git Service

* a-stmaco.ads, exp_util.ads, exp_util.adb, i-cpp.ads, i-cpp.adb:
[pf3gnuchains/gcc-fork.git] / gcc / ada / i-cpp.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                       I N T E R F A C E S . C P P                        --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004, 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 with Ada.Tags;                use Ada.Tags;
35 with System;                  use System;
36 with System.Storage_Elements; use System.Storage_Elements;
37 with Unchecked_Conversion;
38
39 package body Interfaces.CPP is
40
41    --  The declarations below need (extensive) comments ???
42
43    subtype Cstring is String (Positive);
44    type Cstring_Ptr is access all Cstring;
45    type Tag_Table is array (Natural range <>) of Vtable_Ptr;
46    pragma Suppress_Initialization (Tag_Table);
47
48    type Type_Specific_Data is record
49       Idepth        : Natural;
50       Expanded_Name : Cstring_Ptr;
51       External_Tag  : Cstring_Ptr;
52       HT_Link       : Tag;
53       Ancestor_Tags : Tag_Table (Natural);
54    end record;
55
56    type Vtable_Entry is record
57      Pfn : System.Address;
58    end record;
59
60    type Type_Specific_Data_Ptr is access all Type_Specific_Data;
61    type Vtable_Entry_Array is array (Positive range <>) of Vtable_Entry;
62
63    type VTable is record
64       Prims_Ptr : Vtable_Entry_Array (Positive);
65       TSD       : Type_Specific_Data_Ptr;
66    end record;
67
68    --------------------------------------------------------
69    -- Unchecked Conversions for Tag, Vtable_Ptr, and TSD --
70    --------------------------------------------------------
71
72    function To_Type_Specific_Data_Ptr is
73      new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);
74
75    function To_Address is
76      new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);
77
78    ---------------------------------------------
79    -- Unchecked Conversions for String Fields --
80    ---------------------------------------------
81
82    function To_Cstring_Ptr is
83      new Unchecked_Conversion (Address, Cstring_Ptr);
84
85    function To_Address is
86      new Unchecked_Conversion (Cstring_Ptr, Address);
87
88    -----------------------
89    -- Local Subprograms --
90    -----------------------
91
92    function Length (Str : Cstring_Ptr) return Natural;
93    --  Length of string represented by the given pointer (treating the
94    --  string as a C-style string, which is Nul terminated).
95
96    -----------------------
97    -- CPP_CW_Membership --
98    -----------------------
99
100    function CPP_CW_Membership
101      (Obj_Tag : Vtable_Ptr;
102       Typ_Tag : Vtable_Ptr) return Boolean
103    is
104       Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
105    begin
106       return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
107    end CPP_CW_Membership;
108
109    ---------------------------
110    -- CPP_Get_Expanded_Name --
111    ---------------------------
112
113    function CPP_Get_Expanded_Name (T : Vtable_Ptr) return Address is
114    begin
115       return To_Address (T.TSD.Expanded_Name);
116    end CPP_Get_Expanded_Name;
117
118    --------------------------
119    -- CPP_Get_External_Tag --
120    --------------------------
121
122    function CPP_Get_External_Tag (T : Vtable_Ptr) return Address is
123    begin
124       return To_Address (T.TSD.External_Tag);
125    end CPP_Get_External_Tag;
126
127    -------------------------------
128    -- CPP_Get_Inheritance_Depth --
129    -------------------------------
130
131    function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural is
132    begin
133       return T.TSD.Idepth;
134    end CPP_Get_Inheritance_Depth;
135
136    -------------------------
137    -- CPP_Get_Prim_Op_Address --
138    -------------------------
139
140    function CPP_Get_Prim_Op_Address
141      (T        : Vtable_Ptr;
142       Position : Positive) return Address
143    is
144    begin
145       return T.Prims_Ptr (Position).Pfn;
146    end CPP_Get_Prim_Op_Address;
147
148    -----------------------
149    -- CPP_Get_RC_Offset --
150    -----------------------
151
152    function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset is
153       pragma Warnings (Off, T);
154    begin
155       return 0;
156    end CPP_Get_RC_Offset;
157
158    -------------------------------
159    -- CPP_Get_Remotely_Callable --
160    -------------------------------
161
162    function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean is
163       pragma Warnings (Off, T);
164    begin
165       return True;
166    end CPP_Get_Remotely_Callable;
167
168    -----------------
169    -- CPP_Get_TSD --
170    -----------------
171
172    function CPP_Get_TSD  (T : Vtable_Ptr) return Address is
173    begin
174       return To_Address (T.TSD);
175    end CPP_Get_TSD;
176
177    --------------------
178    -- CPP_Inherit_DT --
179    --------------------
180
181    procedure CPP_Inherit_DT
182     (Old_T   : Vtable_Ptr;
183      New_T   : Vtable_Ptr;
184      Entry_Count : Natural)
185    is
186    begin
187       if Old_T /= null then
188          New_T.Prims_Ptr (1 .. Entry_Count)
189            := Old_T.Prims_Ptr (1 .. Entry_Count);
190       end if;
191    end CPP_Inherit_DT;
192
193    ---------------------
194    -- CPP_Inherit_TSD --
195    ---------------------
196
197    procedure CPP_Inherit_TSD
198      (Old_TSD : Address;
199       New_Tag : Vtable_Ptr)
200    is
201       TSD : constant Type_Specific_Data_Ptr :=
202               To_Type_Specific_Data_Ptr (Old_TSD);
203
204       New_TSD : Type_Specific_Data renames New_Tag.TSD.all;
205
206    begin
207       if TSD /= null then
208          New_TSD.Idepth := TSD.Idepth + 1;
209          New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
210            := TSD.Ancestor_Tags (0 .. TSD.Idepth);
211       else
212          New_TSD.Idepth := 0;
213       end if;
214
215       New_TSD.Ancestor_Tags (0) := New_Tag;
216    end CPP_Inherit_TSD;
217
218    ---------------------------
219    -- CPP_Set_Expanded_Name --
220    ---------------------------
221
222    procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : Address) is
223    begin
224       T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
225    end CPP_Set_Expanded_Name;
226
227    --------------------------
228    -- CPP_Set_External_Tag --
229    --------------------------
230
231    procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : Address) is
232    begin
233       T.TSD.External_Tag := To_Cstring_Ptr (Value);
234    end CPP_Set_External_Tag;
235
236    -------------------------------
237    -- CPP_Set_Inheritance_Depth --
238    -------------------------------
239
240    procedure CPP_Set_Inheritance_Depth
241      (T     : Vtable_Ptr;
242       Value : Natural)
243    is
244    begin
245       T.TSD.Idepth := Value;
246    end CPP_Set_Inheritance_Depth;
247
248    -----------------------------
249    -- CPP_Set_Prim_Op_Address --
250    -----------------------------
251
252    procedure CPP_Set_Prim_Op_Address
253      (T        : Vtable_Ptr;
254       Position : Positive;
255       Value    : Address)
256    is
257    begin
258       T.Prims_Ptr (Position).Pfn := Value;
259    end CPP_Set_Prim_Op_Address;
260
261    -----------------------
262    -- CPP_Set_RC_Offset --
263    -----------------------
264
265    procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset) is
266       pragma Warnings (Off, T);
267       pragma Warnings (Off, Value);
268    begin
269       null;
270    end CPP_Set_RC_Offset;
271
272    -------------------------------
273    -- CPP_Set_Remotely_Callable --
274    -------------------------------
275
276    procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean) is
277       pragma Warnings (Off, T);
278       pragma Warnings (Off, Value);
279    begin
280       null;
281    end CPP_Set_Remotely_Callable;
282
283    -----------------
284    -- CPP_Set_TSD --
285    -----------------
286
287    procedure CPP_Set_TSD (T : Vtable_Ptr; Value : Address) is
288    begin
289       T.TSD := To_Type_Specific_Data_Ptr (Value);
290    end CPP_Set_TSD;
291
292    --------------------
293    -- Displaced_This --
294    --------------------
295
296    function Displaced_This
297     (Current_This : System.Address;
298      Vptr         : Vtable_Ptr;
299      Position     : Positive)
300      return         System.Address
301    is
302       pragma Warnings (Off, Vptr);
303       pragma Warnings (Off, Position);
304
305    begin
306       return Current_This;
307
308       --  why is the following here commented out ???
309       --  + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
310    end Displaced_This;
311
312    -------------------
313    -- Expanded_Name --
314    -------------------
315
316    function Expanded_Name (T : Vtable_Ptr) return String is
317       Result : constant Cstring_Ptr := T.TSD.Expanded_Name;
318    begin
319       return Result (1 .. Length (Result));
320    end Expanded_Name;
321
322    ------------------
323    -- External_Tag --
324    ------------------
325
326    function External_Tag (T : Vtable_Ptr) return String is
327       Result : constant Cstring_Ptr := T.TSD.External_Tag;
328    begin
329       return Result (1 .. Length (Result));
330    end External_Tag;
331
332    ------------
333    -- Length --
334    ------------
335
336    function Length (Str : Cstring_Ptr) return Natural is
337       Len : Integer := 1;
338
339    begin
340       while Str (Len) /= ASCII.Nul loop
341          Len := Len + 1;
342       end loop;
343
344       return Len - 1;
345    end Length;
346
347 end Interfaces.CPP;