[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section outlines the ASIS application development and usage cycle. We first take a sample problem and present an ASIS application that offers a solution; then we show how to build the executable with ASIS-for-GNAT and how to prepare an ASIS “Context” to be processed by the program; and finally we show the output produced by our program when it is applied to itself.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
We wish to process some set of Ada compilation units as follows: for every unit, print its full expanded Ada name, whether this unit is a spec(1), a body or a subunit, and whether this unit is a user-defined unit, an Ada predefined unit or an implementation-specific unit (such as a part of a Run-Time Library).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
An ASIS application must use the following sequence of calls:
Asis.Implementation.Initialize (...);
This initializes the ASIS implementation’s internal data structures.
In general, calling an ASIS
query is erroneous unless the Initialize
procedure has been invoked.
Asis.Ada_Environments.Associate (...);
This call is the only means to define a value of a variable of the
ASIS limited private type Context
.
The value represents some specific
association of the ASIS Context
with the “external world”. The way
of making this association and the meaning of the corresponding
parameters of the Associate
query are implementation-specific,
but as soon as this association has been made and a Context
variable
is opened, the ASIS Context
designated by this variable may be
considered to be a set of ASIS Compilation_Unit
s
available through the ASIS queries.
Asis.Ada_Environments.Open (...);
Opening an ASIS Context
variable makes the corresponding Context
accessible to all ASIS queries.
After opening the Context
, an ASIS application can start obtaining
ASIS Compilation_Unit
s from it, can further analyze Compilation_Unit
s
by decomposing them into ASIS Element
s, etc.
ASIS relies on the fact that the content of a Context
remains “frozen”
as long as the Context
remains open.
It is erroneous
to change through some non-ASIS program any data
structures used by an ASIS implementation to define and implement
this Context
while the Context
is open.
Compilation_Unit
s
from the Context
, to decompose units into syntactic Element
s,
to query syntactic and semantic properties of these
Element
s and so on.
Asis.Ada_Environments.Close (...);
After closing the Context
it is impossible to retrieve any information
from it. All the values of the ASIS objects of Compilation_Unit
,
Element
and Line
types obtained when this Context
was open become
obsolete, and it is erroneous
to use them after the Context
was closed.
The content of this Context
need not be frozen while
the Context
remains closed. Note that a closed Context
keeps its
association with the “external world” and it may be opened again with
the same association. Note also that the content (that is, the
corresponding set of ASIS Compilation_Unit
s) of the Context
may be
different from what was in the Context
before, because the “external
world” may have changed while the Context
remained closed.
Asis.Ada_Environments.Dissociate (...);
This query breaks the association between the corresponding ASIS
Context
and the “external world”, and the corresponding Context
variable becomes undefined.
Asis.Implementation.Finalize (...);
This releases all the resources used by an ASIS implementation.
An application can perform these steps in a loop. It may initialize and
finalize an ASIS implementation several times, it may associate and dissociate
the same Context
several times while an ASIS implementation remains
initialized, and it may open and close the same Context
several times while
the Context
keeps its association with the “external world”.
An application can have several ASIS Context
s opened at a time (the upper
limit is implementation-specific), and for each open Context
, an application
can process several Compilation_Unit
s obtained from this Context
at a time
(the upper limit is also implementation-specific). ASIS-for-GNAT
does not
impose any special limitations on the number of ASIS Context
s and on the
number of the ASIS Compilation_Unit
s processed at a time, as long as an ASIS
application is within the general resource limitations of the underlying
system.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The rest of this section assumes that you have ASIS-for-GNAT properly installed as an Ada library.
To get the executable for the ASIS application from
An ASIS Application that Solves the Problem (assuming
that it is located in your current directory as the Ada source file named
‘example1.adb’), invoke gnatmake
as follows(2):
$ gnatmake example1.adb -largs -lasis |
For more details concerning compiling ASIS applications and building executables for them with ASIS-for-GNAT see Compiling, Binding and Linking Applications with ASIS-for-GNAT.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The general ASIS implementation technique is to use some information generated by the underlying Ada compiler as the basis for retrieving information from the Ada environment. As a consequence, an ASIS application can process only legal (compilable) Ada code, and in most of the cases to make a compilation unit “visible” for ASIS means to compile this unit (probably with some ASIS-specific options)
ASIS-for-GNAT uses tree output files (or, in short, tree files) to capture information about an Ada unit from an Ada environment. A tree file is generated by GNAT, and it contains a snapshot of the compiler’s internal data structures at the end of the successful compilation of the corresponding source file.
To create a tree file for a unit contained in some source file, you should compile this file with the ‘-gnatct’ compiler option. If you want to apply the program described in section An ASIS Application that Solves the Problem to itself, compile the source of this application with the command:
$ gcc -c -gnatct example1.adb |
and as a result, GNAT will generate the tree file named ‘example1.adt’ in the current directory.
For more information on how to generate and deal with tree files, see
ASIS Context
, and ASIS Tutorials.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To complete our example, let’s execute our ASIS application. If you have
followed all the steps described in this chapter,
your current directory should contain the executable ‘example1’
(‘example1.exe’ on a Windows platform)
and the tree file ‘example1.adt’.
If we run
our application, it will process an ASIS Context
defined by one tree file
‘example1.adt’ (for more details about defining an ASIS Context
see
ASIS Context
, and the ASIS-for-GNAT Reference Manual).
The result will be:
A |
Note that the tree file
contains the full syntactic and semantic information not only
about the unit compiled by the given call to gcc
, but also about all
the units upon which this unit depends semantically; that is why you can see
in the output list a number of units which are not mentioned in our example.
In the current version of ASIS-for-GNAT, ASIS implementation components are considered user-defined, rather than implementation-specific, units.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by root on February 6, 2012 using texi2html 1.82.