OSDN Git Service

2004-03-05 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-tags.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                             A D A . T A G S                              --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the  contents of the part following the private keyword. --
14 --                                                                          --
15 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
16 -- terms of the  GNU General Public License as published  by the Free Soft- --
17 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
18 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
24 -- MA 02111-1307, USA.                                                      --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- GNAT was originally developed  by the GNAT team at  New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
35 --                                                                          --
36 ------------------------------------------------------------------------------
37
38 with System;
39 with System.Storage_Elements;
40 with Unchecked_Conversion;
41
42 package Ada.Tags is
43
44    pragma Elaborate_Body;
45
46    type Tag is private;
47
48    function Expanded_Name (T : Tag) return String;
49
50    function External_Tag (T : Tag) return String;
51
52    function Internal_Tag (External : String) return Tag;
53
54    Tag_Error : exception;
55
56 private
57
58    ----------------------------------------------------------------
59    --  Abstract procedural interface for the GNAT dispatch table --
60    ----------------------------------------------------------------
61
62    --  GNAT's Dispatch Table format is customizable in order to match the
63    --  format used in another langauge. GNAT supports programs that use
64    --  two different dispatch table format at the same time: the native
65    --  format that supports Ada 95 tagged types and which is described in
66    --  Ada.Tags and a foreign format for types that are imported from some
67    --  other language (typically C++) which is described in interfaces.cpp.
68    --  The runtime information kept for each tagged type is separated into
69    --  two objects: the Dispatch Table and the Type Specific Data record.
70    --  These two objects are allocated statically using the constants:
71
72    --      DT Size  = DT_Prologue_Size  + Nb_Prim * DT_Entry_Size
73    --      TSD Size = TSD_Prologue_Size + (1 + Idepth)  * TSD_Entry_Size
74
75    --  where Nb_prim is the number of primitive operations of the given
76    --  type and Idepth its inheritance depth.
77
78    --  The compiler generates calls to the following SET routines to
79    --  initialize those structures and uses the GET functions to
80    --  retreive the information when needed
81
82    package SSE renames System.Storage_Elements;
83
84    function CW_Membership (Obj_Tag : Tag; Typ_Tag : Tag) return Boolean;
85    --  Given the tag of an object and the tag associated to a type, return
86    --  true if Obj is in Typ'Class.
87
88    function Get_Expanded_Name (T : Tag) return System.Address;
89    --  Retrieve the address of a null terminated string containing
90    --  the expanded name
91
92    function Get_External_Tag (T : Tag) return System.Address;
93    --  Retrieve the address of a null terminated string containing
94    --  the external name
95
96    function Get_Prim_Op_Address
97      (T        : Tag;
98       Position : Positive) return System.Address;
99    --  Given a pointer to a dispatch Table (T) and a position in the DT
100    --  this function returns the address of the virtual function stored
101    --  in it (used for dispatching calls)
102
103    function Get_Inheritance_Depth (T : Tag) return Natural;
104    --  Given a pointer to a dispatch Table, retrieves the value representing
105    --  the depth in the inheritance tree (used for membership).
106
107    function Get_RC_Offset (T : Tag) return SSE.Storage_Offset;
108    --  Return the Offset of the implicit record controller when the object
109    --  has controlled components. O otherwise.
110
111    pragma Export (Ada, Get_RC_Offset, "ada__tags__get_rc_offset");
112    --  This procedure is used in s-finimp to compute the deep routines
113    --  it is exported manually in order to avoid changing completely the
114    --  organization of the run time.
115
116    function Get_Remotely_Callable (T : Tag) return Boolean;
117    --  Return the value previously set by Set_Remotely_Callable
118
119    function  Get_TSD (T : Tag) return System.Address;
120    --  Given a pointer T to a dispatch Table, retreives the address of the
121    --  record containing the Type Specific Data generated by GNAT
122
123    procedure Inherit_DT
124     (Old_T   : Tag;
125      New_T   : Tag;
126      Entry_Count : Natural);
127    --  Entry point used to initialize the DT of a type knowing the tag
128    --  of the direct ancestor and the number of primitive ops that are
129    --  inherited (Entry_Count).
130
131    procedure Inherit_TSD (Old_TSD : System.Address; New_Tag : Tag);
132    --  Entry point used to initialize the TSD of a type knowing the
133    --  TSD of the direct ancestor.
134
135    function Parent_Size
136      (Obj : System.Address;
137       T   : Tag) return SSE.Storage_Count;
138    --  Computes the size the ancestor part of a tagged extension object
139    --  whose address is 'obj' by calling the indirectly _size function of
140    --  the ancestor. The ancestor is the parent of the type represented by
141    --  tag T. This function assumes that _size is always in slot 1 of
142    --  the dispatch table.
143
144    pragma Export (Ada, Parent_Size, "ada__tags__parent_size");
145    --  This procedure is used in s-finimp and is thus exported manually
146
147    function Parent_Tag (T : Tag) return Tag;
148    --  Obj is the address of a tagged object. Parent_Tag fetch the tag of the
149    --  immediate ancestor (parent) of the type associated with Obj.
150
151    pragma Export (Ada, Parent_Tag, "ada__tags__parent_tag");
152    --  This procedure is used in s-finimp and is thus exported manually
153
154    procedure Register_Tag (T : Tag);
155    --  Insert the Tag and its associated external_tag in a table for the
156    --  sake of Internal_Tag
157
158    procedure Set_Inheritance_Depth
159      (T     : Tag;
160       Value : Natural);
161    --  Given a pointer to a dispatch Table, stores the value representing
162    --  the depth in the inheritance tree (the second parameter). Used during
163    --  elaboration of the tagged type.
164
165    procedure Set_Prim_Op_Address
166      (T        : Tag;
167       Position : Positive;
168       Value    : System.Address);
169    --  Given a pointer to a dispatch Table (T) and a position in the
170    --  dispatch Table put the address of the virtual function in it
171    --  (used for overriding)
172
173    procedure Set_TSD (T : Tag; Value : System.Address);
174    --  Given a pointer T to a dispatch Table, stores the address of the record
175    --  containing the Type Specific Data generated by GNAT
176
177    procedure Set_Expanded_Name (T : Tag; Value : System.Address);
178    --  Set the address of the string containing the expanded name
179    --  in the Dispatch table
180
181    procedure Set_External_Tag (T : Tag; Value : System.Address);
182    --  Set the address of the string containing the external tag
183    --  in the Dispatch table
184
185    procedure Set_RC_Offset (T : Tag; Value : SSE.Storage_Offset);
186    --  Sets the Offset of the implicit record controller when the object
187    --  has controlled components. Set to O otherwise.
188
189    procedure Set_Remotely_Callable (T : Tag; Value : Boolean);
190    --  Set to true if the type has been declared in a context described
191    --  in E.4 (18)
192
193    DT_Prologue_Size : constant SSE.Storage_Count :=
194                         SSE.Storage_Count
195                           (Standard'Address_Size / System.Storage_Unit);
196    --  Size of the first part of the dispatch table
197
198    DT_Entry_Size : constant SSE.Storage_Count :=
199                      SSE.Storage_Count
200                        (Standard'Address_Size / System.Storage_Unit);
201    --  Size of each primitive operation entry in the Dispatch Table.
202
203    TSD_Prologue_Size : constant SSE.Storage_Count :=
204                          SSE.Storage_Count
205                            (6 * Standard'Address_Size / System.Storage_Unit);
206    --  Size of the first part of the type specific data
207
208    TSD_Entry_Size : constant SSE.Storage_Count :=
209      SSE.Storage_Count (Standard'Address_Size / System.Storage_Unit);
210    --  Size of each ancestor tag entry in the TSD
211
212    type Address_Array is array (Natural range <>) of System.Address;
213
214    type Dispatch_Table;
215    type Tag is access all Dispatch_Table;
216
217    type Type_Specific_Data;
218    type Type_Specific_Data_Ptr is access all Type_Specific_Data;
219
220    function To_Type_Specific_Data_Ptr is
221      new Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
222
223    function To_Address is
224      new Unchecked_Conversion (Type_Specific_Data_Ptr, System.Address);
225
226    --  Primitive dispatching operations are always inlined, to facilitate
227    --  use in a minimal/no run-time environment for high integrity use.
228
229    pragma Inline_Always (CW_Membership);
230    pragma Inline_Always (Get_Expanded_Name);
231    pragma Inline_Always (Get_Inheritance_Depth);
232    pragma Inline_Always (Get_Prim_Op_Address);
233    pragma Inline_Always (Get_RC_Offset);
234    pragma Inline_Always (Get_Remotely_Callable);
235    pragma Inline_Always (Get_TSD);
236    pragma Inline_Always (Inherit_DT);
237    pragma Inline_Always (Inherit_TSD);
238    pragma Inline_Always (Register_Tag);
239    pragma Inline_Always (Set_Expanded_Name);
240    pragma Inline_Always (Set_External_Tag);
241    pragma Inline_Always (Set_Inheritance_Depth);
242    pragma Inline_Always (Set_Prim_Op_Address);
243    pragma Inline_Always (Set_RC_Offset);
244    pragma Inline_Always (Set_Remotely_Callable);
245    pragma Inline_Always (Set_TSD);
246
247 end Ada.Tags;