File : a-tags-hie.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT RUN-TIME COMPONENTS                         --
   4 --                                                                          --
   5 --                             A D A . T A G S                              --
   6 --                                                                          --
   7 --                                 B o d y                                  --
   8 --                                                                          --
   9 --          Copyright (C) 1992-2010, 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 3,  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.                                     --
  17 --                                                                          --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  21 --                                                                          --
  22 -- You should have received a copy of the GNU General Public License and    --
  23 -- a copy of the GCC Runtime Library Exception along with this program;     --
  24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
  25 -- <http://www.gnu.org/licenses/>.                                          --
  26 --                                                                          --
  27 -- GNAT was originally developed  by the GNAT team at  New York University. --
  28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  29 --                                                                          --
  30 ------------------------------------------------------------------------------
  31 
  32 --  This is the HI-E version of this file. Some functionality has been
  33 --  removed in order to simplify this run-time unit.
  34 
  35 with Ada.Unchecked_Conversion;
  36 with System.Storage_Elements; use System.Storage_Elements;
  37 
  38 package body Ada.Tags is
  39 
  40    -----------------------
  41    -- Local Subprograms --
  42    -----------------------
  43 
  44    function Length (Str : Cstring_Ptr) return Natural;
  45    --  Length of string represented by the given pointer (treating the string
  46    --  as a C-style string, which is Nul terminated).
  47 
  48    --  Unchecked Conversions
  49 
  50    function To_Addr_Ptr is
  51       new Ada.Unchecked_Conversion (System.Address, Addr_Ptr);
  52 
  53    function To_Address is
  54      new Ada.Unchecked_Conversion (Tag, System.Address);
  55 
  56    function To_Type_Specific_Data_Ptr is
  57      new Ada.Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
  58 
  59    -------------------
  60    -- Expanded_Name --
  61    -------------------
  62 
  63    function Expanded_Name (T : Tag) return String is
  64       Result  : Cstring_Ptr;
  65       TSD_Ptr : Addr_Ptr;
  66       TSD     : Type_Specific_Data_Ptr;
  67 
  68    begin
  69       if T = No_Tag then
  70          raise Tag_Error;
  71       end if;
  72 
  73       TSD_Ptr := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
  74       TSD     := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
  75       Result  := TSD.Expanded_Name;
  76       return Result (1 .. Length (Result));
  77    end Expanded_Name;
  78 
  79    ------------------
  80    -- External_Tag --
  81    ------------------
  82 
  83    function External_Tag (T : Tag) return String is
  84       Result  : Cstring_Ptr;
  85       TSD_Ptr : Addr_Ptr;
  86       TSD     : Type_Specific_Data_Ptr;
  87 
  88    begin
  89       if T = No_Tag then
  90          raise Tag_Error;
  91       end if;
  92 
  93       TSD_Ptr := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
  94       TSD     := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
  95       Result  := TSD.External_Tag;
  96       return Result (1 .. Length (Result));
  97    end External_Tag;
  98 
  99    ------------
 100    -- Length --
 101    ------------
 102 
 103    function Length (Str : Cstring_Ptr) return Natural is
 104       Len : Integer;
 105 
 106    begin
 107       Len := 1;
 108       while Str (Len) /= ASCII.NUL loop
 109          Len := Len + 1;
 110       end loop;
 111 
 112       return Len - 1;
 113    end Length;
 114 
 115    ----------------
 116    -- Parent_Tag --
 117    ----------------
 118 
 119    function Parent_Tag (T : Tag) return Tag is
 120       TSD_Ptr : Addr_Ptr;
 121       TSD     : Type_Specific_Data_Ptr;
 122 
 123    begin
 124       if T = No_Tag then
 125          raise Tag_Error;
 126       end if;
 127 
 128       TSD_Ptr := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
 129       TSD     := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
 130 
 131       --  The Parent_Tag of a root-level tagged type is defined to be No_Tag.
 132       --  The first entry in the Ancestors_Tags array will be null for such
 133       --  a type, but it's better to be explicit about returning No_Tag in
 134       --  this case.
 135 
 136       if TSD.Idepth = 0 then
 137          return No_Tag;
 138       else
 139          return TSD.Tags_Table (1);
 140       end if;
 141    end Parent_Tag;
 142 
 143 end Ada.Tags;