comp.lang.ada
 help / color / mirror / Atom feed
* ASIS-FOR-GNAT, anyone?
@ 2001-08-08 12:44 Lance
  2001-08-08 17:08 ` Jean-Pierre Rosen
  2001-08-09 15:14 ` Samuel T. Harris
  0 siblings, 2 replies; 3+ messages in thread
From: Lance @ 2001-08-08 12:44 UTC (permalink / raw)


I've just been assigned a new project at work dealing with ASIS.  Not
knowing Ada to begin with has made this quite a challenge.  I was
wondering if someone could help with what seems like an easy thing to
do.

Say I wanted to count all of the assignment statements in a compilation
unit.  Assume also that I wanted to print out the name of each
subprogram or block in which the assignment statement resides.  I cannot
seem to find an ASIS function that would allow me to get to this
information.  I devised my own crude way of doing it but there must be a
simple solution that I am overlooking.

Thanks for your help in advance.


This is an example of what I am talking about:

procedure Red is
  A : Integer;

  procedure Blue is
    B: Integer;
    begin
      B := 2;
    end Blue;

  begin
    A := 1;
  end Red;

-----------

Now, let stmt1 be "B := 2" and stmt2 be "A := 1".  My function would
return:

Subprogram_Name ( stmt1 ) = "Blue"
Subprogram_Name ( stmt2 ) = "Red"








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

* Re: ASIS-FOR-GNAT, anyone?
  2001-08-08 12:44 ASIS-FOR-GNAT, anyone? Lance
@ 2001-08-08 17:08 ` Jean-Pierre Rosen
  2001-08-09 15:14 ` Samuel T. Harris
  1 sibling, 0 replies; 3+ messages in thread
From: Jean-Pierre Rosen @ 2001-08-08 17:08 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

"Lance" <lance.earwood@yahoo.com> a �crit dans le message news: 3B713442.80F2DCE3@yahoo.com...
> I've just been assigned a new project at work dealing with ASIS.  Not
> knowing Ada to begin with has made this quite a challenge.  I was
> wondering if someone could help with what seems like an easy thing to
> do.
>
There are two specific mailing lists for ASIS questions. From the ASIS page:

ASISWG/ASISRG maintains two electronic mail forums: one for general ASIS information and one for technical discussions about ASIS
itself. To have your email address added to one or both of these forums, send email to either:

SIGAda-ASIS-Request@ACM.Org
or
SIGAda-ASIS-Tech-Request@ACM.Org
with the following information:
Name
Company address (on as many lines as necessary)
Phone Number
FAX Number
E-mail address(es)
World Wide Web URL
Mailing address, if different from Company address

You'll find very helpful people there (my experience).

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





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

* Re: ASIS-FOR-GNAT, anyone?
  2001-08-08 12:44 ASIS-FOR-GNAT, anyone? Lance
  2001-08-08 17:08 ` Jean-Pierre Rosen
@ 2001-08-09 15:14 ` Samuel T. Harris
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel T. Harris @ 2001-08-09 15:14 UTC (permalink / raw)


Lance wrote:
> 
> I've just been assigned a new project at work dealing with ASIS.  Not
> knowing Ada to begin with has made this quite a challenge.  I was
> wondering if someone could help with what seems like an easy thing to
> do.
> 
> Say I wanted to count all of the assignment statements in a compilation
> unit.  Assume also that I wanted to print out the name of each
> subprogram or block in which the assignment statement resides.  I cannot
> seem to find an ASIS function that would allow me to get to this
> information.  I devised my own crude way of doing it but there must be a
> simple solution that I am overlooking.
> 
> Thanks for your help in advance.
> 
> This is an example of what I am talking about:
> 
> procedure Red is
>   A : Integer;
> 
>   procedure Blue is
>     B: Integer;
>     begin
>       B := 2;
>     end Blue;
> 
>   begin
>     A := 1;
>   end Red;
> 
> -----------
> 
> Now, let stmt1 be "B := 2" and stmt2 be "A := 1".  My function would
> return:
> 
> Subprogram_Name ( stmt1 ) = "Blue"
> Subprogram_Name ( stmt2 ) = "Red"

My own experience up to now has been ASIS version 1 for Ada 83.
I know there are some differences with ASIS for Ada 95, but I
hope my comments will get you on the right road.

You want to use asis.elements.traverse, a generic, in which
you define you own routine which is called on each element
in the semantic tree.

This routine will have a case statement on the asis.elements.element_kind
where you are concerned with a_statement where you need another case
statement on asis.statements.kind where you are concerned with
an assignment statement.

As an optimization, you can safely use abandon_children
as the control when you see your assignment statement
since nothing within is of interest to your problem.

Having found an assignment statment, you are may be interested
in the following ...

Using asis.text.element_span to show where in the code
the assignment statment resides.

Incrementing your counter.

Using a loop on asis.elements.enclosing_element to "unwrap"
the element noting any subprogram or package structures
you find on the way to a asis.elements.nil_element (meaning
you have unwrapped outside the compilation unit itself
and can terminate the loop).

I hope these references are not too different in ASIS for Ada 95
and I hope they are helpful in pointing you into the right
directions.

-- 
Samuel T. Harris, Senior Software Engineer II
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"



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

end of thread, other threads:[~2001-08-09 15:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-08 12:44 ASIS-FOR-GNAT, anyone? Lance
2001-08-08 17:08 ` Jean-Pierre Rosen
2001-08-09 15:14 ` Samuel T. Harris

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