File: asis_ug_3.html

package info (click to toggle)
asis 2008-5
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 9,724 kB
  • ctags: 615
  • sloc: ada: 95,867; makefile: 259; xml: 19
file content (570 lines) | stat: -rw-r--r-- 27,499 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
<HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created on May, 22  2008 by texi2html 1.64-gnat-1 -->
<!-- 
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
 
-->
<HEAD>
<TITLE>ASIS-for-GNAT User's Guide: Getting Started</TITLE>
<META NAME="description" CONTENT="ASIS-for-GNAT User's Guide: Getting Started">
<META NAME="keywords" CONTENT="ASIS-for-GNAT User's Guide: Getting Started">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64-gnat-1">

</HEAD>

<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">

<A NAME="SEC9"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_2.html#SEC8"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC10"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H1> 2. Getting Started </H1>
<!--docid::SEC9::-->
<P>

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.
</P><P>

<BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> 
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="asis_ug_3.html#SEC10">2.1 The Problem</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="asis_ug_3.html#SEC11">2.2 An ASIS Application that Solves the Problem</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="asis_ug_3.html#SEC12">2.3 Required Sequence of Calls</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="asis_ug_3.html#SEC13">2.4 Building the Executable for an ASIS application</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="asis_ug_3.html#SEC14">2.5 Preparing Data for an ASIS Application - Generating Tree Files</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="asis_ug_3.html#SEC15">2.6 Running an ASIS Application</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
</TABLE></BLOCKQUOTE>
<P>

<A NAME="The Problem"></A>
<HR SIZE="6">
<A NAME="SEC10"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC11"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 2.1 The Problem </H2>
<!--docid::SEC10::-->
<P>

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<A NAME="DOCF1" HREF="asis_ug_fot.html#FOOT1">(1)</A>, 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).
</P><P>

<A NAME="An ASIS Application that Solves the Problem"></A>
<HR SIZE="6">
<A NAME="SEC11"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC10"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC12"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC12"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 2.2 An ASIS Application that Solves the Problem </H2>
<!--docid::SEC11::-->
<P>

<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=+0><pre>with Ada.Wide_Text_IO;        use Ada.Wide_Text_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;

--  ASIS-specific context clauses:
with Asis;
with Asis.Implementation;
with Asis.Ada_Environments;
with Asis.Compilation_Units;
with Asis.Exceptions;
with Asis.Errors;

procedure Example1 is
   My_Context : Asis.Context;
<A NAME="IDX6"></A>   --  ASIS Context is an abstraction of an Ada compilation environment,
   --  it defines a set of ASIS Compilation Units available through
   --  ASIS queries

begin
   --  first, by initializing an ASIS implementation, we make it
   --  ready for work
   Asis.Implementation.Initialize ("-ws");
<A NAME="IDX7"></A>   --  The "-ws" parameter of the Initialize procedure means
   --  "turn off all the ASIS warnings"

   --  then we define our Context by making an association with
   --  the "physical" environment:
   Asis.Ada_Environments.Associate
    (My_Context, "My Asis Context", "-CA");
<A NAME="IDX8"></A>   --  "-CA" as a Context parameter means "consider all the tree
   --  files in the current directory"
   --  See ASIS-for-GNAT Reference Manual for the description of the
   --  parameters of the Associate query, see also chapter
   --  "ASIS Context" for the description of different kinds of
   --  ASIS Context in case of ASIS-for-GNAT

   --  by opening a Context we make it ready for processing by ASIS
   --  queries
   Asis.Ada_Environments.Open (My_Context);
<A NAME="IDX9"></A>
   Processing_Units: declare
      Next_Unit : Asis.Compilation_Unit;
<A NAME="IDX10"></A>      --  ASIS Compilation_Unit is the abstraction to represent Ada
      --  compilation units as described in RM 95

      All_Units : Asis.Compilation_Unit_List :=
      --  ASIS lists are one-dimensional unconstrained arrays.
      --  Therefore, when declaring an object of an ASIS list type,
      --  we have to provide either a constraint or explicit
      --  initialization expression:

         Asis.Compilation_Units.Compilation_Units (My_Context);
      --  The Compilation_Units query returns a list of all the units
      --  contained in an ASIS Context
   begin
      Put_Line
        ("A Context contains the following compilation units:");
      New_Line;
      for I in All_Units'Range loop
         Next_Unit := All_Units (I);
         Put ("   ");

         --  to get a unit name, we just need a Unit_Full_Name
         --  query. ASIS uses Wide_String as a string type,
         --  that is why we are using Ada.Wide_Text_IO

         Put (Asis.Compilation_Units.Unit_Full_Name (Next_Unit));
<A NAME="IDX11"></A>
         --  to get more info about a unit, we ask about unit class
         --  and about unit origin

         case Asis.Compilation_Units.Unit_Kind (Next_Unit) is
<A NAME="IDX12"></A>            when Asis.A_Library_Unit_Body =&#62;
               Put (" (body)");
            when Asis.A_Subunit =&#62;
               Put (" (subunit)");
            when others =&#62;
               Put (" (spec)");
         end case;

         case Asis.Compilation_Units.Unit_Origin (Next_Unit) is
<A NAME="IDX13"></A>            when Asis.An_Application_Unit =&#62;
               Put_Line (" - user-defined unit");
            when Asis.An_Implementation_Unit =&#62;
               Put_Line (" - implementation-specific unit");
            when Asis.A_Predefined_Unit =&#62;
               Put_Line (" - Ada predefined unit");
            when Asis.Not_An_Origin =&#62;
               Put_Line
                 (" - unit does not actually exist in a Context");
         end case;

      end loop;
   end Processing_Units;

   --  Cleaning up: we have to close out the Context, break its
   --  association with the external environment and finalize
   --  our ASIS implementation to release all the resources used:
   Asis.Ada_Environments.Close (My_Context);
<A NAME="IDX14"></A>   Asis.Ada_Environments.Dissociate (My_Context);
<A NAME="IDX15"></A>   Asis.Implementation.Finalize;
<A NAME="IDX16"></A>
exception
   when Asis.Exceptions.ASIS_Inappropriate_Context |
<A NAME="IDX17"></A>        Asis.Exceptions.ASIS_Inappropriate_Compilation_Unit |
<A NAME="IDX18"></A>        Asis.Exceptions.ASIS_Failed =&#62;
<A NAME="IDX19"></A>
      --  we check not for all the ASIS-defined exceptions, but only
      --  those of them which can actually be raised in our ASIS
      --  application.
      --
      --  If an ASIS exception is raised, we output the ASIS error
      --  status and the ASIS diagnosis string:

      Put_Line ("ASIS exception is raised:");
      Put_Line ("ASIS diagnosis is:");
      Put_Line (Asis.Implementation.Diagnosis);
      Put      ("ASIS error status is: ");
      Put_Line
        (Asis.Errors.Error_Kinds'Wide_Image
           (Asis.Implementation.Status));
<A NAME="IDX20"></A>end Example1;
</FONT></pre></td></tr></table></P><P>

<A NAME="Required Sequence of Calls"></A>
<HR SIZE="6">
<A NAME="SEC12"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC11"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC13"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC13"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 2.3 Required Sequence of Calls </H2>
<!--docid::SEC12::-->
<P>

An ASIS application must use the following sequence of calls:
</P><P>

<OL>
<LI>
<CODE>Asis.Implementation.Initialize (...);</CODE>
<A NAME="IDX21"></A>
<P>

This initializes the ASIS implementation's internal data structures.
In general, calling an ASIS
query is erroneous unless the <CODE>Initialize</CODE> procedure has been invoked.
<A NAME="IDX22"></A>
</P><P>

<LI>
<CODE>Asis.Ada_Environments.Associate (...);</CODE>
<A NAME="IDX23"></A>
<P>

This call is the only means to define a value of a variable of the
ASIS limited private type <CODE>Context</CODE>.
<A NAME="IDX24"></A>
The value represents some specific
association of the ASIS <CODE>Context</CODE> with the "external world". The way
of making this association and the meaning of the corresponding
parameters of the <CODE>Associate</CODE> query are implementation-specific,
but as soon as this association has been made and a <CODE>Context</CODE> variable
is opened, the ASIS <CODE>Context</CODE> designated by this variable may be
considered to be a set of ASIS <CODE>Compilation_Unit</CODE>s
<A NAME="IDX25"></A>
available through the ASIS queries.
</P><P>

<LI>
<CODE>Asis.Ada_Environments.Open (...);</CODE>
<A NAME="IDX26"></A>
<P>

Opening an ASIS <CODE>Context</CODE> variable makes the corresponding <CODE>Context</CODE>
accessible to all ASIS queries.
</P><P>

 After opening the <CODE>Context</CODE>, an ASIS application can start obtaining
 ASIS <CODE>Compilation_Unit</CODE>s from it, can further analyze <CODE>Compilation_Unit</CODE>s
 by decomposing them into ASIS <CODE>Element</CODE>s, etc.
<A NAME="IDX27"></A>
<A NAME="IDX28"></A>
</P><P>

 ASIS relies on the fact that the content of a <CODE>Context</CODE> remains "frozen"
 as long as the <CODE>Context</CODE> remains open.
 It is erroneous
<A NAME="IDX29"></A>
to change through some non-ASIS program any data
 structures used by an ASIS implementation to define and implement
 this <CODE>Context</CODE> while the <CODE>Context</CODE> is open.
</P><P>

<LI>
Now all the ASIS queries can be used. It is possible to access <CODE>Compilation_Unit</CODE>s
from the <CODE>Context</CODE>, to decompose units into syntactic <CODE>Element</CODE>s,
<A NAME="IDX30"></A>
<A NAME="IDX31"></A>
to query syntactic and semantic properties of these
<CODE>Element</CODE>s and so on.
<P>

<LI>
<CODE>Asis.Ada_Environments.Close (...);</CODE>
<A NAME="IDX32"></A>
<P>

After closing the <CODE>Context</CODE> it is impossible to retrieve any information
from it. All the values of the ASIS objects of <CODE>Compilation_Unit</CODE>,
<A NAME="IDX33"></A>
<A NAME="IDX34"></A>
<CODE>Element</CODE>
<A NAME="IDX35"></A>
and <CODE>Line</CODE>
<A NAME="IDX36"></A>
types obtained when this <CODE>Context</CODE> was open become
obsolete, and it is erroneous
<A NAME="IDX37"></A>
to use them after the <CODE>Context</CODE> was closed.
 The content of this <CODE>Context</CODE> need not be frozen while
 the <CODE>Context</CODE> remains closed. Note that a closed <CODE>Context</CODE> 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 <CODE>Compilation_Unit</CODE>s) of the <CODE>Context</CODE> may be
 different from what was in the <CODE>Context</CODE> before, because the "external
 world" may have changed while the <CODE>Context</CODE> remained closed.
</P><P>

<LI>
<CODE>Asis.Ada_Environments.Dissociate (...);</CODE>
<A NAME="IDX38"></A>
<P>

This query breaks the association between the corresponding ASIS
<CODE>Context</CODE> and the "external world", and the corresponding <CODE>Context</CODE>
variable becomes undefined.
</P><P>

<LI>
<CODE>Asis.Implementation.Finalize (...);</CODE>
<A NAME="IDX39"></A>
<P>

This releases all the resources used by an ASIS implementation.
</OL>
<P>

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 <CODE>Context</CODE> several times while an ASIS implementation remains
initialized, and it may open and close the same <CODE>Context</CODE> several times while
the <CODE>Context</CODE> keeps its association with the "external world".
<A NAME="IDX40"></A>
</P><P>

An application can have several ASIS <CODE>Context</CODE>s opened at a time (the upper
limit is implementation-specific), and for each open <CODE>Context</CODE>, an application
can process several <CODE>Compilation_Unit</CODE>s obtained from this <CODE>Context</CODE> at a time
(the upper limit is also implementation-specific). ASIS-for-GNAT
<A NAME="IDX41"></A>
does not
impose any special limitations on the number of ASIS <CODE>Context</CODE>s and on the
number of the ASIS <CODE>Compilation_Unit</CODE>s processed at a time, as long as an ASIS
application is within the general resource limitations of the underlying
system.
</P><P>

<A NAME="Building the Executable for an ASIS application"></A>
<HR SIZE="6">
<A NAME="SEC13"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC12"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC14"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC14"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 2.4 Building the Executable for an ASIS application </H2>
<!--docid::SEC13::-->
<P>

The rest of this section assumes that you have ASIS-for-GNAT properly
installed as an Ada library.
<A NAME="IDX42"></A>
</P><P>

To get the executable for the ASIS application from
<A HREF="asis_ug_3.html#SEC11">2.2 An ASIS Application that Solves the Problem</A> (assuming
that it is located in your current directory as the Ada source file named
<TT>`example1.adb'</TT>), invoke <CODE>gnatmake</CODE> as follows<A NAME="DOCF2" HREF="asis_ug_fot.html#FOOT2">(2)</A>:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=+0><pre>$ gnatmake example1.adb -largs -lasis
</FONT></pre></td></tr></table></P><P>

For more details concerning compiling ASIS applications and building
executables for them with ASIS-for-GNAT see
<A HREF="asis_ug_11.html#SEC52">10. Compiling, Binding and Linking Applications with ASIS-for-GNAT</A>.
</P><P>

<A NAME="Preparing Data for an ASIS Application - Generating Tree Files"></A>
<HR SIZE="6">
<A NAME="SEC14"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC13"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC15"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC15"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 2.5 Preparing Data for an ASIS Application - Generating Tree Files </H2>
<!--docid::SEC14::-->
<P>

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)
</P><P>

ASIS-for-GNAT uses <EM>tree output files</EM> (or, in short, <EM>tree files</EM>)
to capture
<A NAME="IDX43"></A>
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.
</P><P>

To create a tree file for a unit contained in some source file, you should
compile this file with the <SAMP>`-gnatc'</SAMP> and <SAMP>`-gnatt'</SAMP> compiler options.
<A NAME="IDX44"></A>
<A NAME="IDX45"></A>
If you want to apply
the program described in section
<A HREF="asis_ug_3.html#SEC11">2.2 An ASIS Application that Solves the Problem</A> to itself,
compile the source of this application with the command:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=+0><pre>$ gcc -c -gnatc -gnatt example1.adb
</FONT></pre></td></tr></table></P><P>

and as a result, GNAT will generate the tree file named <TT>`example1.adt'</TT> in the current
directory.
</P><P>

For more information on how to generate and deal with tree files, see
<A HREF="asis_ug_5.html#SEC24">4. ASIS <CODE>Context</CODE></A>, and <A HREF="asis_ug_8.html#SEC45">7. ASIS Tutorials</A>.
</P><P>

<A NAME="Running an ASIS Application"></A>
<HR SIZE="6">
<A NAME="SEC15"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC14"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 2.6 Running an ASIS Application </H2>
<!--docid::SEC15::-->
<P>

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 <TT>`example1'</TT>
(<TT>`example1.exe'</TT> on a Windows platform)
and the tree file <TT>`example1.adt'</TT>.
If we run
our application, it will process an ASIS <CODE>Context</CODE> defined by one tree file
<TT>`example1.adt'</TT> (for more details about defining an ASIS <CODE>Context</CODE> see
<A HREF="asis_ug_5.html#SEC24">4. ASIS <CODE>Context</CODE></A>, and the <CITE>ASIS-for-GNAT Reference Manual</CITE>).
<A NAME="IDX46"></A>
The result will be:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=+0><pre>   A <CODE>Context</CODE> contains the following compilation units:

      Standard (spec) - Ada predefined unit
      Example1 (body) - user-defined unit
      Ada (spec) - Ada predefined unit
      Ada.Wide_Text_IO (spec) - Ada predefined unit
      Ada.IO_Exceptions (spec) - Ada predefined unit
      Ada.Streams (spec) - Ada predefined unit
      System (spec) - Ada predefined unit
      System.File_Control_Block (spec) - implementation-specific unit
      Interfaces (spec) - Ada predefined unit
      Interfaces.C_Streams (spec) - implementation-specific unit
      System.Parameters (spec) - implementation-specific unit
      System.WCh_Con (spec) - implementation-specific unit
      Ada.Characters (spec) - Ada predefined unit
      Ada.Characters.Handling (spec) - Ada predefined unit
      Asis (spec) - user-defined unit
      A4G (spec) - user-defined unit
      A4G.A_Types (spec) - user-defined unit
      Ada.Characters.Latin_1 (spec) - Ada predefined unit
      GNAT (spec) - implementation-specific unit
      GNAT.OS_Lib (spec) - implementation-specific unit
      GNAT.Strings (spec) - implementation-specific unit
      Unchecked_Deallocation (spec) - Ada predefined unit
      Sinfo (spec) - user-defined unit
      Types (spec) - user-defined unit
      Uintp (spec) - user-defined unit
      Alloc (spec) - user-defined unit
      Table (spec) - user-defined unit
      Urealp (spec) - user-defined unit
      A4G.Int_Knds (spec) - user-defined unit
      Asis.Implementation (spec) - user-defined unit
      Asis.Errors (spec) - user-defined unit
      Asis.Ada_Environments (spec) - user-defined unit
      Asis.Compilation_Units (spec) - user-defined unit
      Asis.Ada_Environments.Containers (spec) - user-defined unit
      Asis.Exceptions (spec) - user-defined unit
      System.Unsigned_Types (spec) - implementation-specific unit
</FONT></pre></td></tr></table></P><P>

Note that the tree file
<A NAME="IDX47"></A>
contains the full syntactic and semantic information not only
about the unit compiled by the given call to <CODE>gcc</CODE>, 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.
</P><P>

In the current version of ASIS-for-GNAT, ASIS implementation components are considered
user-defined, rather than implementation-specific, units.
</P><P>

<A NAME="ASIS Overview"></A>
<HR SIZE="6">
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_3.html#SEC9"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_4.html#SEC16"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_15.html#SEC56">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="asis_ug_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>  
<FONT SIZE="-1">
This document was generated
by <I>Mail Server</I> on <I>May, 22  2008</I>
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html/"><I>texi2html</I></A>

</BODY>
</HTML>