comp.lang.ada
 help / color / mirror / Atom feed
* Package name as string
@ 2011-02-15 18:33 Rego
  2011-02-15 19:16 ` Jeffrey Carter
  2011-02-16  7:06 ` Per Sandberg
  0 siblings, 2 replies; 7+ messages in thread
From: Rego @ 2011-02-15 18:33 UTC (permalink / raw)


Does someone know a function/package which I get the name of the (other) procedure in use as a string?

I mean, I have a procedure which needs to make a call that returns its own name in a string form:
--
with Package_I_Wanna_Know;
procedure Blabla is
   I_Want_To_Read_This_String : String;

begin
   I_Want_To_Read_This_String := Package_I_Wanna_Know.Wanted_Function;
end Blabla;
--
And so, I_Want_To_Read_This_String = "Blabla".

Tks!



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Package name as string
  2011-02-15 18:33 Package name as string Rego
@ 2011-02-15 19:16 ` Jeffrey Carter
  2011-02-16  7:06 ` Per Sandberg
  1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2011-02-15 19:16 UTC (permalink / raw)


On 02/15/2011 11:33 AM, Rego wrote:
> Does someone know a function/package which I get the name of the (other) procedure in use as a string?
>
> I mean, I have a procedure which needs to make a call that returns its own name in a string form:
> --
> with Package_I_Wanna_Know;
> procedure Blabla is
>     I_Want_To_Read_This_String : String;
>
> begin
>     I_Want_To_Read_This_String := Package_I_Wanna_Know.Wanted_Function;
> end Blabla;
> --
> And so, I_Want_To_Read_This_String = "Blabla".

You can use PragmARC.Reflection to obtain a unit's name. This is part of the 
PragmAda Reusable Components:

pragmada.x10hosting.com

-- 
Jeff Carter
"Strange women lying in ponds distributing swords
is no basis for a system of government."
Monty Python & the Holy Grail
66



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Package name as string
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Per Sandberg @ 2011-02-16  7:06 UTC (permalink / raw)


Simplest way with GNAT is:

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


On 02/15/2011 07:33 PM, Rego wrote:
> Does someone know a function/package which I get the name of the (other) procedure in use as a string?
>
> I mean, I have a procedure which needs to make a call that returns its own name in a string form:
> --
> with Package_I_Wanna_Know;
> procedure Blabla is
>     I_Want_To_Read_This_String : String;
>
> begin
>     I_Want_To_Read_This_String := Package_I_Wanna_Know.Wanted_Function;
> end Blabla;
> --
> And so, I_Want_To_Read_This_String = "Blabla".
>
> Tks!



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Package name as string
  2011-02-16  7:06 ` Per Sandberg
@ 2011-02-16  8:52   ` Dmitry A. Kazakov
  2011-02-16 10:51     ` Georg Bauhaus
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2011-02-16  8:52 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Package name as string
  2011-02-16  8:52   ` Dmitry A. Kazakov
@ 2011-02-16 10:51     ` Georg Bauhaus
  2011-02-16 13:03       ` Dmitry A. Kazakov
  2011-02-16 13:14       ` Rego
  0 siblings, 2 replies; 7+ messages in thread
From: Georg Bauhaus @ 2011-02-16 10:51 UTC (permalink / raw)


On 16.02.11 09:52, Dmitry A. Kazakov wrote:
> On Wed, 16 Feb 2011 08:06:45 +0100, Per Sandberg wrote:

> 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;
> 

This is akin to what Pragmada.Reflection does.
It uses instances of a generic, an abstract type,
and does then not rely on -11.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Package name as string
  2011-02-16 10:51     ` Georg Bauhaus
@ 2011-02-16 13:03       ` Dmitry A. Kazakov
  2011-02-16 13:14       ` Rego
  1 sibling, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2011-02-16 13:03 UTC (permalink / raw)


On Wed, 16 Feb 2011 11:51:38 +0100, Georg Bauhaus wrote:

> On 16.02.11 09:52, Dmitry A. Kazakov wrote:
>> On Wed, 16 Feb 2011 08:06:45 +0100, Per Sandberg wrote:
> 
>> 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;
>> 
> 
> This is akin to what Pragmada.Reflection does.
> It uses instances of a generic, an abstract type,
> and does then not rely on -11.

11 = ".Name.Dummy"'Length

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Package name as string
  2011-02-16 10:51     ` Georg Bauhaus
  2011-02-16 13:03       ` Dmitry A. Kazakov
@ 2011-02-16 13:14       ` Rego
  1 sibling, 0 replies; 7+ messages in thread
From: Rego @ 2011-02-16 13:14 UTC (permalink / raw)


Thanks people,
It helps me a lot.
Regards.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-02-16 13:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2011-02-16 10:51     ` Georg Bauhaus
2011-02-16 13:03       ` Dmitry A. Kazakov
2011-02-16 13:14       ` Rego

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