File: black_box.scr

package info (click to toggle)
asis 2005-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,424 kB
  • ctags: 27
  • sloc: ada: 73,883; makefile: 201
file content (230 lines) | stat: -rw-r--r-- 11,839 bytes parent folder | download | duplicates (10)
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
---------------------------------------------------------------
--  This is an ASIStant script which contains a sequence     --
--  of the ASIS queries doing some black-box processing      --
--  of ASIS Compilation Units. The task is to add some more  --
--  steps to this processing to get some more information    --
--  from the ASIS Context                                    --
---------------------------------------------------------------

--  defining Cont - variable of Asis.Context Type to work with
set (Cont)

--  initializing the ASIS implementation
initialize ("")

--  Associating Cont as having no name and made up by the tree
--  files contained in the current directory
associate (Cont, "", "")

--  and opening it
open (Cont)

--  obtaining the ASIS Compilation Unit named Ex_Proc from our
--  Context
set (CU_1, Compilation_Unit_Body ("Ex_Proc", cont))

--  and displaying its full expanded Ada name
print (Unit_Full_Name (CU_1))

---------------------------------------------------------------
--  And now, let's come to some exercises                    --
--                                                           --
--  resume the script by the parameterless "run" command     --
--  when you are ready to get the first task                 --
---------------------------------------------------------------
pause

---------------------------------------------------------------
--  The ASIS Context being processed contains some other     --
--  Compilation Units. Let's try to get some information     --
--  about them, starting from obtaining some other units     --
--  from the Context                                         --
--                                                           --
--  Before doing the first exercise, have a short look at    --
--  the beginning of the ASIS package Asis.Compilation_Units --
--  to see, what queries can be used to obtain Compilation   --
--  Units from a Context (subclauses 10.6-10.10)             --
--                                                           --
--  resume the script when ready                             --
---------------------------------------------------------------
pause


---------------------------------------------------------------
--  Task 1: Get the ASIS Compilation Unit containing the     --
--          declaration of the library package Ex_Pack1      --
--                                                           --
--  Hints for the solution:                                  --
--  1. Find out, what of the queries from 10.6-10.10 you     --
--     should use for this.                                  --
--  2. Use the ASIStant command                              --
--                                                           --
--        set (CU_2, <Needed_Query> (<arguments>))           --
--                                                           --
--     to get the needed unit as the value of the ASIStant   --
--     variable CU_2                                         --
--  3. Display the ASIS debug image of CU_2 to see, what     --
--     have you got:                                         --
--        print (CU_2)                                       --
--                                                           --
--  Type these commands in the interactive mode. Do not be   --
--  afraid if you do some errors - just see the diagnostic   --
--  and try again.                                           --
--                                                           --
--  When you complete the task, resume the script to see a   --
--  possible correct solution and to get the next task       --
---------------------------------------------------------------
pause

---------------------------------------------------------------
--  A possible solution for task 1 is:                       --
--  obtaining the needed unit (Library_Unit_Declaration is   --
--  the query to use):                                       --
--                                                           --
set   (CU_2, Library_Unit_Declaration ("Ex_Pack1", cont))    --
--                                                           --
--  and displaying its debug image                           --
print (CU_2)                                                 --
---------------------------------------------------------------
--
-- resume the script to get the next task
pause

---------------------------------------------------------------
--  Task 2: Get all the Compilation Units contained in the   --
--          given context.                                   --
--                                                           --
--  Hints for the solution:                                  --
--  1. This task duffers from the previous one in two things:--
--     - you should use another query;                       --
--     - you should work with the ASIS variable of the type  --
--       Compilation_Unit_List                               --
--  2. The required sequence of the ASIS/ASIStant calls      --
--     is the same, as for the previous task:                --
--                                                           --
--        set   (All_Units, <Needed_Query> (<arguments>      --
--        print (All_Units)                                  --
--                                                           --
--     but here the print command will display the list      --
--     length and the debug images of all the elements of the--
--     list                                                  --
--  Type these commands in the interactive mode. When        --
--  complete, resume the script to see a possible correct    --
--  solution and to get the next task                        --
---------------------------------------------------------------
pause

---------------------------------------------------------------
--  The solution for task 2 is:                              --
--  obtaining all the units from a Context (Compilation_Units--
--  is the query to use):                                    --
--                                                           --
set   (All_Units, Compilation_Units (cont))                  --
--                                                           --
--  and displaying the result                                --
print (All_Units)                                            --
---------------------------------------------------------------
--
-- resume the script to get the next task
pause

---------------------------------------------------------------
--  Task 3: let's do something more interesting - obtaining  --
--          some information about semantic dependencies     --
--          among units. Take the spec of the library package--
--          Ex_Pack1 and ask for the corresponding body for  --
--          it                                               --
--                                                           --
--  Hints for the solution:                                  --
--  1. You need to browse the spec of the ASIS package       --
--     Asis.Compilation_Units some more - have a look at     --
--     subclauses 10.11-10.14                                --
--  2. You already have the spec of Ex_Pack1 as the value of --
--     the variable CU_2.                                    --
--  3. The required sequence of the ASIS/ASIStant calls is:  --
--                                                           --
--        set   (CU_2_Body, <Needed_Query> (CU_2))           --
--        print (CU_2_Body)                                  --
--                                                           --
--  Type these commands in the interactive mode. When        --
--  complete, resume the script to see a possible correct    --
--  solution and to get the next task                        --
---------------------------------------------------------------
pause

---------------------------------------------------------------
--  The solution for task 3 is:                              --
--  obtaining the corresponding body for a unit              --
--  (Corresponding_Body is the query to use)                  --
--                                                           --
set   (CU_2_Body, Corresponding_Body (CU_2))                 --
--                                                           --
--  and displaying the result                                --
 print (CU_2_Body)                                           --
---------------------------------------------------------------
--
-- resume the script to get the last task
pause
---------------------------------------------------------------
--  Task 4: You've probably noticed the package named GNAT   --
--          when displaying the whole content of the context --
--          now get its childs and display the result list   --
--                                                           --
--  Hints for the solution:                                  --
--  1. You have to start from obtaining the unit named "GNAT"--
--     from the Context - you need it as an argument to pass --
--     to the corresponding query                            --
--  2. When getting this unit, display its debug image to    --
--     make sure that you really have got it.                --
--  3. The required sequence of the calls is                 --
--                                                           --
--        set   (CU_GNAT, <Needed_Query1> (<arguments1>))    --
--        print (CU_GNAT)                                    --
--                                                           --
--        set   (GNAT_Childs, <Need_Query2> (<arguments2>))  --
--        print (GNAT_Childs)                                --
--                                                           --
--  4. Pay your attention at the origin of the resulting     --
--     units.                                                --
--                                                           --
--  Type these commands in the interactive mode. When        --
--  complete, resume the script to see a correct solution    --
---------------------------------------------------------------
pause

---------------------------------------------------------------
--  A solution for task 4 is:                                --
--  obtaining the library unit declaration for the package   --
--  named GNAT                                               --
--                                                           --
set   (CU_GNAT, Library_Unit_Declaration ("GNAT", cont))     --
--                                                           --
--  and displaying it:                                       --
--                                                           --
print (CU_GNAT)                                              --
                                                             --
--  Resume the script to see the final part of the solution  --
pause                                                        --
--                                                           --
set   (GNAT_Childs, Corresponding_Children (CU_GNAT))        --
print (GNAT_Childs)                                          --
---------------------------------------------------------------

--  this is the end of the tasks included in this exercise.
--  Now ASIStant is in interactive mode and you can play
--  around with other queries as you want. Then resume the
--  script for the last time to see the final steps of an
--  ASIS application cycle and to finish the job
pause

--  closing the Context
Close (Cont)

-- breaking its connection with the "external word"
Dissociate (Cont)

--  and finalizing the ASIS implementation itself
Finalize ("")

-- and this completes the exercise script
quit