comp.lang.ada
 help / color / mirror / Atom feed
From: James Alan Farrell <jfarrell@nospam.com>
Subject: Re: ASIS Question: Looking up procedure names.
Date: Wed, 18 May 2005 11:14:49 -0400
Date: 2005-05-18T11:14:49-04:00	[thread overview]
Message-ID: <428b5c41$1_2@newsfeed.slurp.net> (raw)
In-Reply-To: <6ivu7111ovojq41kpt9u4rv8rknpv58mhu@4ax.com>

[-- Attachment #1: Type: text/plain, Size: 4561 bytes --]

Peter,
Here is how to get the full name:

First, from call get the entity called

procedure get_called_entity(ProcCall : asis.element)
    CalledEntity : asis.element;
begin
    CalledEntity :=
       asis.statements.corresponding_called_entity(ProcCall);
end;

CalledEntity is a declaration.  To get it's name, use 
asis.declarations.names, which returns a list.  To turn that into a wide 
string, use asis.declarations.defining_name_image(name_list[0]).

Now to get the package name, you can use asis.elements.enclosing_element 
to get the declaration of the package in which the entity is declared. 
This also returns a decl (the package decl) and you can use the same 
method to get it's name.  Something like:


procedure get_called_entity(ProcCall : asis.element)
    CalledEntity : asis.element;
    PackageDecl  : asis.element;
begin
    -- get the called entity
    CalledEntity :=
        asis.statements.corresponding_called_entity(ProcCall);

    -- get the called entity's package
    PackageDecl := asis.elements.enclosing_element(CalledEntity);

    -- get the package name
    declare
       NameList : asis.element_list :=
            asis.declarations.names(PackageDecl);
       PackageName : program_text :=
            asis.declarations.defining_name_image(NameList[0]);
    begin
       Ada.Text_IO.Put(PackageName);
    end;

    -- we need to put our own dot between the package name and
    -- the entity name
    Ada.Text_IO.Put(".");

    -- get the called entity's name
    declare
       NameList : asis.element_list :=
            asis.declarations.names(CalledEntity);
       ProcName : program_text :=
            asis.declarations.defining_name_image(NameList[0]);
    begin
       Ada.Text_IO.Put(ProcName);
    end;

    Ada.Text_IO.New_Line;

end;

This assumes that the called procedure was declared at the top level of 
the package.  You have to verify that by calling
(asis.elements.declaration_kind(PackageDecl) = a_package_declaration) or
(asis.elements.declaration_kind(PackageDecl) =
                                           a_package_body_declaration)

The called proc could be nested inside another proc, in which case the 
parent proc's name will be printed.  In addition, procs can be declared 
inside block statements (declares) (which, IMHO, is a bit messy and 
should be avoided), in which case I'm not sure how the call to
asis.declarations.names(PackageDecl) will react -- it might raise an 
innappropriate_element exception.

Good luck and hope this helps,
James



James Alan Farrell wrote:
> On Sat, 07 May 2005 20:10:46 GMT, "Peter C. Chapin"
> <pchapin@sover.net> wrote:
> 
> Peter,
> I'm working on a project that uses ASIS.  Unfortunately I am on
> vacation and my notes on this are at work.  I believe that what you
> are trying to do can be done.  If you can wait until next week, I can
> look at my notes then.
> 
> As for the list of procedure names, this comes about because
> asis.declarations is used for all declarations, not just procedure
> declarations.  Thus
> 
>    A, B : integer;
> 
> has to be support.  Get the name here, and you will get a list of two
> elements.  For subprograms, yes there will always be only one name.
> (Renames clauses are handled differently)
> 
> James Alan Farrell
> 
> 
>>Hi! I'm writing an ASIS program and I've encountered a problem that I'm 
>>having trouble figuring out.
>>
>>I have an element that I know is a procedure call statement. What I'm 
>>looking for is the full name of the procedure, including package 
>>membership. So for example
>>
>>with Ada.Text_IO; use Ada.Text_IO;
>>
>>procedure Hello is
>>begin
>> Put_Line("Hello, World");
>>end Hello;
>>
>>When looking at the Put_Line procedure call statement, I want to get the 
>>name "Ada.Text_IO.Put_Line." Is this possible?
>>
>>Starting with the procedure call statement, I can use 
>>Corresponding_Called_Entity to get the procedure declaration. I can then 
>>use Names to get a list of defining names for that declaration (wouldn't 
>>there always be only one such name for procedure declarations?). I can 
>>then convert the first name on this list to program text using 
>>Defining_Name_Image. However, the name returned in this case is just 
>>'Put_Line' and not 'Ada.Text_IO.Put_Line' as desired.
>>
>>I see in Asis.Declarations the function Defining_Prefix that takes 
>>A_Defining_Expanded_Name and returns the prefix. So that tells me what I 
>>need is a way to get A_Defining_Expanded_Name from my procedure call 
>>statement. This is where I'm stuck.
>>
>>TIA
>>
>>Peter
> 
> 


[-- Attachment #2: jfarrell.vcf --]
[-- Type: text/x-vcard, Size: 88 bytes --]

begin:vcard
fn:James Alan Farrell
n:Farrell;James
org:GrammaTech
version:2.1
end:vcard


  reply	other threads:[~2005-05-18 15:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-07 20:10 ASIS Question: Looking up procedure names Peter C. Chapin
2005-05-09  8:49 ` Jean-Pierre Rosen
2005-05-09 11:25   ` Peter C. Chapin
2005-05-09 15:18 ` James Alan Farrell
2005-05-18 15:14   ` James Alan Farrell [this message]
2005-05-18 16:41     ` Jean-Pierre Rosen
2005-05-18 18:08       ` James Alan Farrell
replies disabled

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