comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Package name as string
Date: Wed, 16 Feb 2011 09:52:43 +0100
Date: 2011-02-16T09:52:43+01:00	[thread overview]
Message-ID: <cnk5j1g10cxl.14c1ky4vp4ijn$.dlg@40tude.net> (raw)
In-Reply-To: 9IK6p.32469$2t5.26524@newsfe24.ams2

On Wed, 16 Feb 2011 08:06:45 +0100, Per Sandberg wrote:

> Simplest way with GNAT is:
> 
> with GNAT.Source_Info;
> package body blaa is
>     package_name : constant String := GNAT.Source_Info.Enclosing_Entity;
>     ...
>     ...
> end blaa;

A possible GNAT-independent implementation:

   with Ada.Tags;

   function Name return String is
      type Dummy is tagged limited null record;
      Result : String  := Ada.Tags.Expanded_Name (Dummy'Tag);
   begin
      return Result (Result'First..Result'Last - 11);
   end Name;

To be cut and pasted into each body where it has to be used.

[ Of course with generic instances the question becomes ambiguous. ]

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-02-16  8:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15 18:33 Package name as string Rego
2011-02-15 19:16 ` Jeffrey Carter
2011-02-16  7:06 ` Per Sandberg
2011-02-16  8:52   ` Dmitry A. Kazakov [this message]
2011-02-16 10:51     ` Georg Bauhaus
2011-02-16 13:03       ` Dmitry A. Kazakov
2011-02-16 13:14       ` Rego
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox