From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d4a99b2a2a2899b7 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 18 May 2005 11:14:49 -0400 From: James Alan Farrell Organization: nospam User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: ASIS Question: Looking up procedure names. References: <6ivu7111ovojq41kpt9u4rv8rknpv58mhu@4ax.com> In-Reply-To: <6ivu7111ovojq41kpt9u4rv8rknpv58mhu@4ax.com> Content-Type: multipart/mixed; boundary="------------020401080902050003080807" NNTP-Posting-Host: fw.grammatech.com Message-ID: <428b5c41$1_2@newsfeed.slurp.net> X-Trace: newsfeed.slurp.net 1116429377 209.4.89.67 (18 May 2005 10:16:17 -0500) X-Original-NNTP-Posting-Host: 209.4.89.67 Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!newsfeed00.sul.t-online.de!t-online.de!newsfeed-0.progon.net!progon.net!newsfeed.slurp.net!not-for-mail Xref: g2news1.google.com comp.lang.ada:11079 Date: 2005-05-18T11:14:49-04:00 List-Id: This is a multi-part message in MIME format. --------------020401080902050003080807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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" > 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 > > --------------020401080902050003080807 Content-Type: text/x-vcard; charset=utf-8; name="jfarrell.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="jfarrell.vcf" begin:vcard fn:James Alan Farrell n:Farrell;James org:GrammaTech version:2.1 end:vcard --------------020401080902050003080807--