~ubuntu-branches/ubuntu/hardy/asis/hardy-proposed

« back to all changes in this revision

Viewing changes to tutorial/using_templets/README

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Brenta
  • Date: 2006-08-08 23:02:17 UTC
  • mfrom: (3.1.6 edgy)
  • Revision ID: james.westby@ubuntu.com-20060808230217-8j3ts1m8i83e0apm
Tags: 2005-5

debian/control: add support for alpha and s390.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
This directory contains exercises for building ASIS applications
2
 
based on general traversal of ASIS compilation units. These
3
 
applications are supposed to be built from the set of the ASIS
4
 
Application Templates provided by ASIS-for-GNAT.
5
 
 
6
 
We suggest you to build two ASIS tools - a simple style checker and a
7
 
simple metrics collection tool. Both of them are very typical examples
8
 
of ASIS applications. The corresponding tutorial materials are placed
9
 
into subdirectories 'style_checker' and 'metrics' accordingly.
10
 
 
11
 
Each of this subdirectories has the following structure:
12
 
 
13
 
- readme file - contains the formulation of the problem to solve. The
14
 
                problems is subdivided into two tasks: first -
15
 
                developing a very simple version of the tool; second
16
 
                - enhancing the tool by adding addition
17
 
                functionality.
18
 
 
19
 
- task_1      - our solution for the first task and some hints for
20
 
                the second task;
21
 
 
22
 
- task_2      - our solution for the second task;
23
 
 
24
 
The subdirectory 'test_units' contains a set of Ada components you may
25
 
use to test the ASIS tools.
26
 
 
27
 
It may be the case for an ASIS newcomer, that the first task (that
28
 
is, the development of a simple ASIS tool from the set of the ASIS
29
 
application templates) is more complicated, then the second one
30
 
(adding some new functionality to the existing ASIS tool). If so, you
31
 
may study the solution we provide for the first task as an ASIS
32
 
example and work on the second task only.
33
 
 
34
 
To start working on the tutorial applications, copy ASIS application
35
 
templates from the ASIS distribution (catalog
36
 
asis-[version3]-src/templates) into your working directory.
37
 
 
38
 
The main thing you will have to do to build both style checking and
39
 
metrics tools is replacing the empty bodies of actual Pre- and
40
 
Post-operations in the corresponding subunits with the real code
41
 
(actually, you only need to replace the template for Pre-operation,
42
 
and Post-operation may be empty for both these tools). For the style
43
 
checking tool you can reuse the rest of the code of the ASIS
44
 
application templates. For the metrics tool you will have to modify
45
 
the general unit processing routine (Unit_Processing.Process_Unit) -
46
 
you can output the results only when the whole Element structure of
47
 
the unit has been already processed.
48
 
 
49
 
You may also need to provide additional Ada components (for example -
50
 
in case of the metrics tool, you may want to provide the package
51
 
defining the data structures for collecting the metrics information
52
 
and for printing out the metrics values).
53
 
 
54
 
Let's assume, that the ASIS tools to be built should process all the
55
 
user-defined units in the Context, and that they do not have any
56
 
parameter.
57
 
 
58
 
Our solutions of the tutorial tasks are based on the simplest (and
59
 
the only for the moment) driver provided by the set of the ASIS
60
 
Application Templates - ASIS_Application_Driver_1. To test the
61
 
solution, you have to create the tree files for the Ada units to
62
 
process by the ASIS tool in your current directory.
63
 
 
64
 
And here is the general guideline for developing the actual
65
 
Pre-operation for instantiation Asis.Iterator.Traverse_Element.
66
 
Actual Pre-operation processes a single Element, and they do not know
67
 
in advance what is the kind of their argument Element. So, the first
68
 
thing to do is to define the position of the Element being processed
69
 
in the Element classification hierarchy, and then, depending on the
70
 
Element kind, to do this, that or nothing. As a result, the general
71
 
"template" for actual Pre-operation looks like this:
72
 
 
73
 
procedure Pre_Operation
74
 
  (Element :        Asis.Element;
75
 
   Control : in out Asis.Traverse_Control;
76
 
   State   : in out Traversal_State)
77
 
is
78
 
   Arg_Kind : Asis.Element_Kinds;
79
 
   ...
80
 
begin
81
 
   Arg_Kind := Asis.Elements.Element_Kind (Element);
82
 
 
83
 
   case Arg_Kind is
84
 
      when A_Pragma =>
85
 
         Process_Pragma;
86
 
      when A_Declaration =>
87
 
         Process_Declaration;
88
 
      ...
89
 
      when others =>
90
 
         null;
91
 
   end case;
92
 
   ...
93
 
 
94
 
end Pre_Operation;
95
 
 
96
 
Very often you have to use nested case statements to define the exact
97
 
position of the argument Element in the Element classification
98
 
hierarchy and to provide the specific processing for specific
99
 
subordinate kinds.
 
 
b'\\ No newline at end of file'