OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [ada/] [a-tags.ads] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
------------------------------------------------------------------------------
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-2005, 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,  51  Franklin  Street,  Fifth  Floor, --
24
-- Boston, MA 02110-1301, 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
   pragma Preelaborate_05;
44
   --  In accordance with Ada 2005 AI-362
45
 
46
   type Tag is private;
47
 
48
   No_Tag : constant Tag;
49
 
50
   function Expanded_Name (T : Tag) return String;
51
 
52
   function External_Tag (T : Tag) return String;
53
 
54
   function Internal_Tag (External : String) return Tag;
55
 
56
   function Descendant_Tag
57
     (External : String;
58
      Ancestor : Tag) return Tag;
59
   pragma Ada_05 (Descendant_Tag);
60
 
61
   function Is_Descendant_At_Same_Level
62
     (Descendant : Tag;
63
      Ancestor   : Tag) return Boolean;
64
   pragma Ada_05 (Is_Descendant_At_Same_Level);
65
 
66
   function Parent_Tag (T : Tag) return Tag;
67
   pragma Ada_05 (Parent_Tag);
68
 
69
   Tag_Error : exception;
70
 
71
private
72
   --  The following subprogram specifications are placed here instead of
73
   --  the package body to see them from the frontend through rtsfind.
74
 
75
   ---------------------------------------------------------------
76
   -- Abstract Procedural Interface For The GNAT Dispatch Table --
77
   ---------------------------------------------------------------
78
 
79
   --  GNAT's Dispatch Table format is customizable in order to match the
80
   --  format used in another language. GNAT supports programs that use two
81
   --  different dispatch table formats at the same time: the native format
82
   --  that supports Ada 95 tagged types and which is described in Ada.Tags,
83
   --  and a foreign format for types that are imported from some other
84
   --  language (typically C++) which is described in Interfaces.CPP. The
85
   --  runtime information kept for each tagged type is separated into two
86
   --  objects: the Dispatch Table and the Type Specific Data record. These
87
   --  two objects are allocated statically using the constants:
88
 
89
   --      DT Size  = DT_Prologue_Size  + Nb_Prim * DT_Entry_Size
90
   --      TSD Size = TSD_Prologue_Size + (1 + Idepth)  * TSD_Entry_Size
91
 
92
   --  where Nb_prim is the number of primitive operations of the given
93
   --  type and Idepth its inheritance depth.
94
 
95
   --  In order to set or retrieve information from the Dispatch Table or
96
   --  the Type Specific Data record, GNAT generates calls to Set_XXX or
97
   --  Get_XXX routines, where XXX is the name of the field of interest.
98
 
99
   type Dispatch_Table;
100
   type Tag is access all Dispatch_Table;
101
   type Interface_Tag is access all Dispatch_Table;
102
 
103
   No_Tag : constant Tag := null;
104
 
105
   type Object_Specific_Data (Nb_Prim : Positive);
106
   type Object_Specific_Data_Ptr is access all Object_Specific_Data;
107
   --  Information associated with the secondary dispatch table of tagged-type
108
   --  objects implementing abstract interfaces.
109
 
110
   type Select_Specific_Data (Nb_Prim : Positive);
111
   type Select_Specific_Data_Ptr is access all Select_Specific_Data;
112
   --  A table used to store the primitive operation kind and entry index of
113
   --  primitive subprograms of a type that implements a limited interface.
114
   --  The Select Specific Data table resides in the Type Specific Data of a
115
   --  type. This construct is used in the handling of dispatching triggers
116
   --  in select statements.
117
 
118
   type Type_Specific_Data;
119
   type Type_Specific_Data_Ptr is access all Type_Specific_Data;
120
 
121
   --  Primitive operation kinds. These values differentiate the kinds of
122
   --  callable entities stored in the dispatch table. Certain kinds may
123
   --  not be used, but are added for completeness.
124
 
125
   type Prim_Op_Kind is
126
     (POK_Function,
127
      POK_Procedure,
128
      POK_Protected_Entry,
129
      POK_Protected_Function,
130
      POK_Protected_Procedure,
131
      POK_Task_Entry,
132
      POK_Task_Function,
133
      POK_Task_Procedure);
134
 
135
   Default_Prim_Op_Count : constant Positive := 15;
136
   --  Number of predefined primitive operations added by the Expander for a
137
   --  tagged type. It is utilized for indexing in the two auxiliary tables
138
   --  used for dispatching asynchronous, conditional and timed selects. In
139
   --  order to be space efficient, indexing is performed by subtracting this
140
   --  constant value from the provided position in the auxiliary tables (must
141
   --  match Exp_Disp.Default_Prim_Op_Count).
142
 
143
   package SSE renames System.Storage_Elements;
144
 
145
   function CW_Membership (Obj_Tag : Tag; Typ_Tag : Tag) return Boolean;
146
   --  Given the tag of an object and the tag associated to a type, return
147
   --  true if Obj is in Typ'Class.
148
 
149
   function IW_Membership (This : System.Address; T : Tag) return Boolean;
150
   --  Ada 2005 (AI-251): General routine that checks if a given object
151
   --  implements a tagged type. Its common usage is to check if Obj is in
152
   --  Iface'Class, but it is also used to check if a class-wide interface
153
   --  implements a given type (Iface_CW_Typ in T'Class). For example:
154
   --
155
   --      type I is interface;
156
   --      type T is tagged ...
157
   --
158
   --      function Test (O : in I'Class) is
159
   --      begin
160
   --         return O in T'Class.
161
   --      end Test;
162
 
163
   function Get_Access_Level (T : Tag) return Natural;
164
   --  Given the tag associated with a type, returns the accessibility level
165
   --  of the type.
166
 
167
   function Get_Entry_Index (T : Tag; Position : Positive) return Positive;
168
   --  Return a primitive operation's entry index (if entry) given a dispatch
169
   --  table T and a position of a primitive operation in T.
170
 
171
   function Get_External_Tag (T : Tag) return System.Address;
172
   --  Retrieve the address of a null terminated string containing
173
   --  the external name.
174
 
175
   function Get_Offset_Index
176
     (T        : Interface_Tag;
177
      Position : Positive) return Positive;
178
   --  Given a pointer to a secondary dispatch table (T) and a position of an
179
   --  operation in the DT, retrieve the corresponding operation's position in
180
   --  the primary dispatch table from the Offset Specific Data table of T.
181
 
182
   function Get_Prim_Op_Address
183
     (T        : Tag;
184
      Position : Positive) return System.Address;
185
   --  Given a pointer to a dispatch table (T) and a position in the DT
186
   --  this function returns the address of the virtual function stored
187
   --  in it (used for dispatching calls).
188
 
189
   function Get_Prim_Op_Kind
190
     (T        : Tag;
191
      Position : Positive) return Prim_Op_Kind;
192
   --  Return a primitive operation's kind given a dispatch table T and a
193
   --  position of a primitive operation in T.
194
 
195
   function Get_RC_Offset (T : Tag) return SSE.Storage_Offset;
196
   --  Return the Offset of the implicit record controller when the object
197
   --  has controlled components. O otherwise.
198
 
199
   pragma Export (Ada, Get_RC_Offset, "ada__tags__get_rc_offset");
200
   --  This procedure is used in s-finimp to compute the deep routines
201
   --  it is exported manually in order to avoid changing completely the
202
   --  organization of the run time.
203
 
204
   function Get_Remotely_Callable (T : Tag) return Boolean;
205
   --  Return the value previously set by Set_Remotely_Callable
206
 
207
   procedure Inherit_DT (Old_T : Tag; New_T : Tag; Entry_Count : Natural);
208
   --  Entry point used to initialize the DT of a type knowing the tag
209
   --  of the direct ancestor and the number of primitive ops that are
210
   --  inherited (Entry_Count).
211
 
212
   procedure Inherit_TSD (Old_Tag : Tag; New_Tag : Tag);
213
   --  Initialize the TSD of a type knowing the tag of the direct ancestor
214
 
215
   function OSD (T : Interface_Tag) return Object_Specific_Data_Ptr;
216
   --  Ada 2005 (AI-251): Given a pointer T to a secondary dispatch table,
217
   --  retrieve the address of the record containing the Objet Specific
218
   --  Data table.
219
 
220
   function Parent_Size
221
     (Obj : System.Address;
222
      T   : Tag) return SSE.Storage_Count;
223
   --  Computes the size the ancestor part of a tagged extension object whose
224
   --  address is 'obj' by calling indirectly the ancestor _size function. The
225
   --  ancestor is the parent of the type represented by tag T. This function
226
   --  assumes that _size is always in slot one of the dispatch table.
227
 
228
   pragma Export (Ada, Parent_Size, "ada__tags__parent_size");
229
   --  This procedure is used in s-finimp and is thus exported manually
230
 
231
   procedure Register_Interface_Tag (T : Tag; Interface_T : Tag);
232
   --  Ada 2005 (AI-251): Used to initialize the table of interfaces
233
   --  implemented by a type. Required to give support to IW_Membership.
234
 
235
   procedure Register_Tag (T : Tag);
236
   --  Insert the Tag and its associated external_tag in a table for the
237
   --  sake of Internal_Tag
238
 
239
   procedure Set_Entry_Index (T : Tag; Position : Positive; Value : Positive);
240
   --  Set the entry index of a primitive operation in T's TSD table indexed
241
   --  by Position.
242
 
243
   procedure Set_Num_Prim_Ops (T : Tag; Value : Natural);
244
   --  Set the number of primitive operations in the dispatch table of T. This
245
   --  is used for debugging purposes.
246
 
247
   procedure Set_Offset_Index
248
     (T        : Interface_Tag;
249
      Position : Positive;
250
      Value    : Positive);
251
   --  Set the offset value of a primitive operation in a secondary dispatch
252
   --  table denoted by T, indexed by Position.
253
 
254
   procedure Set_Offset_To_Top
255
     (T     : Tag;
256
      Value : System.Storage_Elements.Storage_Offset);
257
   --  Ada 2005 (AI-251): Initialize the Offset_To_Top field in the prologue of
258
   --  the dispatch table. In primary dispatch tables the value of this field
259
   --  is always 0; in secondary dispatch tables this is the offset to the base
260
   --  of the enclosing type.
261
 
262
   procedure Set_OSD (T : Interface_Tag; Value : System.Address);
263
   --  Given a pointer T to a secondary dispatch table, store the pointer to
264
   --  the record containing the Object Specific Data generated by GNAT.
265
 
266
   procedure Set_Prim_Op_Address
267
     (T        : Tag;
268
      Position : Positive;
269
      Value    : System.Address);
270
   --  Given a pointer to a dispatch Table (T) and a position in the dispatch
271
   --  Table put the address of the virtual function in it (used for
272
   --  overriding).
273
 
274
   procedure Set_Prim_Op_Kind
275
     (T        : Tag;
276
      Position : Positive;
277
      Value    : Prim_Op_Kind);
278
   --  Set the kind of a primitive operation in T's TSD table indexed by
279
   --  Position.
280
 
281
   procedure Set_SSD (T : Tag; Value : System.Address);
282
   --  Given a pointer T to a dispatch Table, stores the pointer to the record
283
   --  containing the Select Specific Data generated by GNAT.
284
 
285
   procedure Set_TSD (T : Tag; Value : System.Address);
286
   --  Given a pointer T to a dispatch Table, stores the address of the record
287
   --  containing the Type Specific Data generated by GNAT.
288
 
289
   procedure Set_Access_Level (T : Tag; Value : Natural);
290
   --  Sets the accessibility level of the tagged type associated with T
291
   --  in its TSD.
292
 
293
   procedure Set_Expanded_Name (T : Tag; Value : System.Address);
294
   --  Set the address of the string containing the expanded name
295
   --  in the Dispatch table.
296
 
297
   procedure Set_External_Tag (T : Tag; Value : System.Address);
298
   --  Set the address of the string containing the external tag
299
   --  in the Dispatch table.
300
 
301
   procedure Set_RC_Offset (T : Tag; Value : SSE.Storage_Offset);
302
   --  Sets the Offset of the implicit record controller when the object
303
   --  has controlled components. Set to O otherwise.
304
 
305
   procedure Set_Remotely_Callable (T : Tag; Value : Boolean);
306
   --  Set to true if the type has been declared in a context described
307
   --  in E.4 (18).
308
 
309
   function SSD (T : Tag) return Select_Specific_Data_Ptr;
310
   --  Given a pointer T to a dispatch Table, retrieves the address of the
311
   --  record containing the Select Specific Data in T's TSD.
312
 
313
   function TSD (T : Tag) return Type_Specific_Data_Ptr;
314
   --  Given a pointer T to a dispatch Table, retrieves the address of the
315
   --  record containing the Type Specific Data generated by GNAT.
316
 
317
   DT_Prologue_Size : constant SSE.Storage_Count :=
318
                        SSE.Storage_Count
319
                          (3 * (Standard'Address_Size / System.Storage_Unit));
320
   --  Size of the first part of the dispatch table
321
 
322
   DT_Signature_Size : constant SSE.Storage_Count :=
323
                         SSE.Storage_Count
324
                           (Standard'Address_Size / System.Storage_Unit);
325
   --  Size of the Signature field of the dispatch table
326
 
327
   DT_Offset_To_Top_Size : constant SSE.Storage_Count :=
328
                            SSE.Storage_Count
329
                              (Standard'Address_Size / System.Storage_Unit);
330
   --  Size of the Offset_To_Top field of the Dispatch Table
331
 
332
   DT_Typeinfo_Ptr_Size : constant SSE.Storage_Count :=
333
                            SSE.Storage_Count
334
                              (Standard'Address_Size / System.Storage_Unit);
335
   --  Size of the Typeinfo_Ptr field of the Dispatch Table
336
 
337
   DT_Entry_Size : constant SSE.Storage_Count :=
338
                     SSE.Storage_Count
339
                       (1 * (Standard'Address_Size / System.Storage_Unit));
340
   --  Size of each primitive operation entry in the Dispatch Table
341
 
342
   TSD_Prologue_Size : constant SSE.Storage_Count :=
343
                         SSE.Storage_Count
344
                          (10 * (Standard'Address_Size / System.Storage_Unit));
345
   --  Size of the first part of the type specific data
346
 
347
   TSD_Entry_Size : constant SSE.Storage_Count :=
348
     SSE.Storage_Count (1 * (Standard'Address_Size / System.Storage_Unit));
349
   --  Size of each ancestor tag entry in the TSD
350
 
351
   type Address_Array is array (Natural range <>) of System.Address;
352
   pragma Suppress (Index_Check, On => Address_Array);
353
   --  The reason we suppress index checks is that in the body, objects
354
   --  of this type are declared with a dummy size of 1, the actual size
355
   --  depending on the number of primitive operations.
356
 
357
   type Signature_Kind is
358
      (Unknown,
359
       Valid_Signature,
360
       Primary_DT,
361
       Secondary_DT,
362
       Abstract_Interface);
363
   for Signature_Kind'Size use 8;
364
   --  Kind of signature found in the header of the dispatch table. These
365
   --  signatures are generated by the frontend and are used by the Check_XXX
366
   --  routines to ensure that the kind of dispatch table managed by each of
367
   --  the routines in this package is correct. This additional check is only
368
   --  performed with this run-time package is compiled with assertions enabled
369
 
370
   --  The signature is a sequence of two bytes. The first byte must have the
371
   --  value Valid_Signature, and the second byte must have a value in the
372
   --  range Primary_DT .. Abstract_Interface. The Unknown value is used by
373
   --  the Check_XXX routines to indicate that the signature is wrong.
374
 
375
   --  Unchecked Conversions
376
 
377
   type Addr_Ptr is access System.Address;
378
   type Tag_Ptr  is access Tag;
379
 
380
   type Signature_Values is
381
      array (1 .. DT_Signature_Size) of Signature_Kind;
382
   --  Type used to see the signature as a sequence of Signature_Kind values
383
 
384
   function To_Addr_Ptr is
385
      new Unchecked_Conversion (System.Address, Addr_Ptr);
386
 
387
   function To_Type_Specific_Data_Ptr is
388
     new Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
389
 
390
   function To_Address is
391
     new Unchecked_Conversion (Interface_Tag, System.Address);
392
 
393
   function To_Address is
394
     new Unchecked_Conversion (Tag, System.Address);
395
 
396
   function To_Address is
397
     new Unchecked_Conversion (Type_Specific_Data_Ptr, System.Address);
398
 
399
   function To_Object_Specific_Data_Ptr is
400
     new Unchecked_Conversion (System.Address, Object_Specific_Data_Ptr);
401
 
402
   function To_Select_Specific_Data_Ptr is
403
     new Unchecked_Conversion (System.Address, Select_Specific_Data_Ptr);
404
 
405
   function To_Signature_Values is
406
     new Unchecked_Conversion (System.Storage_Elements.Storage_Offset,
407
                               Signature_Values);
408
 
409
   function To_Tag_Ptr is
410
     new Unchecked_Conversion (System.Address, Tag_Ptr);
411
 
412
   --  Primitive dispatching operations are always inlined, to facilitate
413
   --  use in a minimal/no run-time environment for high integrity use.
414
 
415
   pragma Inline_Always (CW_Membership);
416
   pragma Inline_Always (IW_Membership);
417
   pragma Inline_Always (Get_Access_Level);
418
   pragma Inline_Always (Get_Entry_Index);
419
   pragma Inline_Always (Get_Offset_Index);
420
   pragma Inline_Always (Get_Prim_Op_Address);
421
   pragma Inline_Always (Get_Prim_Op_Kind);
422
   pragma Inline_Always (Get_RC_Offset);
423
   pragma Inline_Always (Get_Remotely_Callable);
424
   pragma Inline_Always (Inherit_DT);
425
   pragma Inline_Always (Inherit_TSD);
426
   pragma Inline_Always (OSD);
427
   pragma Inline_Always (Register_Interface_Tag);
428
   pragma Inline_Always (Register_Tag);
429
   pragma Inline_Always (Set_Access_Level);
430
   pragma Inline_Always (Set_Entry_Index);
431
   pragma Inline_Always (Set_Expanded_Name);
432
   pragma Inline_Always (Set_External_Tag);
433
   pragma Inline_Always (Set_Num_Prim_Ops);
434
   pragma Inline_Always (Set_Offset_Index);
435
   pragma Inline_Always (Set_Offset_To_Top);
436
   pragma Inline_Always (Set_Prim_Op_Address);
437
   pragma Inline_Always (Set_Prim_Op_Kind);
438
   pragma Inline_Always (Set_RC_Offset);
439
   pragma Inline_Always (Set_Remotely_Callable);
440
   pragma Inline_Always (Set_OSD);
441
   pragma Inline_Always (Set_SSD);
442
   pragma Inline_Always (Set_TSD);
443
   pragma Inline_Always (SSD);
444
   pragma Inline_Always (TSD);
445
 
446
end Ada.Tags;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.