* ASIS Question: Looking up procedure names. @ 2005-05-07 20:10 Peter C. Chapin 2005-05-09 8:49 ` Jean-Pierre Rosen 2005-05-09 15:18 ` James Alan Farrell 0 siblings, 2 replies; 7+ messages in thread From: Peter C. Chapin @ 2005-05-07 20:10 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ASIS Question: Looking up procedure names. 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 1 sibling, 1 reply; 7+ messages in thread From: Jean-Pierre Rosen @ 2005-05-09 8:49 UTC (permalink / raw) Peter C. Chapin a �crit : > 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. ASIS provides only *basic* queries, and this one is not part of it. However, if you download Adasubst or Adacontrol from Adalog's components page (http://www.adalog.fr/compo2.htm), you'll have a package called "Thick_Queries" that provide many useful higher-level queries, including a function called "Full_Name_Image" that does exactly that. The whole stuff is GMGPL, so you can use it in any context. -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ASIS Question: Looking up procedure names. 2005-05-09 8:49 ` Jean-Pierre Rosen @ 2005-05-09 11:25 ` Peter C. Chapin 0 siblings, 0 replies; 7+ messages in thread From: Peter C. Chapin @ 2005-05-09 11:25 UTC (permalink / raw) Jean-Pierre Rosen <rosen@adalog.fr> wrote in news:a68n5d.r91.ln@hunter.axlog.fr: > ASIS provides only *basic* queries, and this one is not part of it. > > However, if you download Adasubst or Adacontrol from Adalog's components > page (http://www.adalog.fr/compo2.htm), you'll have a package called > "Thick_Queries" that provide many useful higher-level queries, including > a function called "Full_Name_Image" that does exactly that. Okay, thanks for the reference. I'll check it out. Peter ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ASIS Question: Looking up procedure names. 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 15:18 ` James Alan Farrell 2005-05-18 15:14 ` James Alan Farrell 1 sibling, 1 reply; 7+ messages in thread From: James Alan Farrell @ 2005-05-09 15:18 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ASIS Question: Looking up procedure names. 2005-05-09 15:18 ` James Alan Farrell @ 2005-05-18 15:14 ` James Alan Farrell 2005-05-18 16:41 ` Jean-Pierre Rosen 0 siblings, 1 reply; 7+ messages in thread From: James Alan Farrell @ 2005-05-18 15:14 UTC (permalink / raw) [-- 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ASIS Question: Looking up procedure names. 2005-05-18 15:14 ` James Alan Farrell @ 2005-05-18 16:41 ` Jean-Pierre Rosen 2005-05-18 18:08 ` James Alan Farrell 0 siblings, 1 reply; 7+ messages in thread From: Jean-Pierre Rosen @ 2005-05-18 16:41 UTC (permalink / raw) James Alan Farrell a �crit : > 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; But use Corresponding_Called_Function if it is a function > > 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]). You meant name_list(1), which language are you using :-) > 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. That's much too simplistic. The SP can be declared in a block statement, or another procedure. If it comes from an instantiation, you'll get extra levels (the SP declaration is in a (pseudo) package, which is itself inside the instantiation, etc. Believe me: use Full_Name_Image (or rewrite it at your convenience), it is GMGPL. It took me a *lot* of time to get it working in all contexts. -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ASIS Question: Looking up procedure names. 2005-05-18 16:41 ` Jean-Pierre Rosen @ 2005-05-18 18:08 ` James Alan Farrell 0 siblings, 0 replies; 7+ messages in thread From: James Alan Farrell @ 2005-05-18 18:08 UTC (permalink / raw) [-- Attachment #1: Type: text/plain, Size: 250 bytes --] Jean-Pierre Rosen wrote: > You meant name_list(1), which language are you using :-) > Nice catch -- we've lifted the asis procedures to C and I'm doing most of my work in C (not my choice -- it needs to work with a large body of existing code). [-- 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-05-18 18:08 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2005-05-18 16:41 ` Jean-Pierre Rosen 2005-05-18 18:08 ` James Alan Farrell
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox