File: asis-extensions-iterator.ads

package info (click to toggle)
asis 2019-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 13,848 kB
  • sloc: ada: 156,772; makefile: 296; sh: 81; xml: 48; csh: 10
file content (270 lines) | stat: -rw-r--r-- 12,542 bytes parent folder | download | duplicates (3)
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
------------------------------------------------------------------------------
--                                                                          --
--                        ASIS-for-GNAT COMPONENTS                          --
--                                                                          --
--             A S I S . E X T E N S I O N S . I T E R A T O R              --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
--         Copyright (C) 2003-2014, Free Software Foundation, Inc.          --
--                                                                          --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software Foundation;  either version 2,  or  (at your option)  any later --
-- version. ASIS-for-GNAT is distributed  in the hope  that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or  FITNESS FOR A PARTICULAR  PURPOSE.  See the GNU General --
-- Public License for more details.  You should have received a copy of the --
-- GNU  General  Public  License  distributed with ASIS-for-GNAT;  see file --
-- COPYING.  If not,  write  to the  Free Software Foundation,  51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA.                         --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- ASIS-for-GNAT was originally developed  by the ASIS-for-GNAT team at the --
-- Software  Engineering  Laboratory  of  the Swiss  Federal  Institute  of --
-- Technology (LGL-EPFL) in Lausanne,  Switzerland, in cooperation with the --
-- Scientific  Research  Computer  Center of  Moscow State University (SRCC --
-- MSU), Russia,  with funding partially provided  by grants from the Swiss --
-- National  Science  Foundation  and  the  Swiss  Academy  of  Engineering --
-- Sciences.  ASIS-for-GNAT is now maintained by  AdaCore                   --
-- (http://www.adacore.com).                                                --
--                                                                          --
------------------------------------------------------------------------------

pragma Ada_2012;

--  This package contains some iterator generics that are more general than the
--  Asis.Iterator.Traverse_Element procedure:
--
--     Traverse_Element -- same as Asis.Iterator.Traverse_Element
--
--     Traverse_Element_Q -- same as Traverse_Element, but passes in the
--     relevant queries, and has pre/post operations for lists as well as for
--     elements. The Q parameter of each Pre/Post op tells how we got here. For
--     example, when we traverse A_Package_Declaration, we will traverse the
--     Names, then the Visible_Part_Declarative_Items, and finally the
--     Private_Part_Declarative_Items. This involves three calls to
--     Pre_List_Operation, passing Q = the corresponding enumeration literals
--     of type Structural_Queries (Names, Visible_Part_Declarative_Items,
--     Private_Part_Declarative_Items), which are overloaded with the names of
--     the query functions themselves. This allows clients to tell whether a
--     given declaration is in the visible or private part, for example. If
--     Element is the N'th element of an Element_List, the Index parameter is
--     passed N, and Is_List_Element is True. Otherwise (not a list element),
--     Element is the N'th child of its parent, and Index = N, and
--     Is_List_Element is False.
--
--     Traverse_Unit -- similar to Traverse_Element, but traverses a
--     Compilation_Unit. This is needed because a Compilation_Unit is not an
--     element.
--
--     Traverse_Unit_Q -- traverses a Compilation_Unit with queries, list
--     operations, and list index as for Traverse_Element_Q.
--
--  All of these procedures take a Traverse_Nils parameter, which controls
--  whether Nil_Elements are traversed -- False means Nil_Elements are ignored.
--
--  Also a Syntactic parameter, which controls how operator calls and
--  prefix-notation calls are traversed. Syntactic = True means the traversal
--  follows the syntax, so for "A+B", we traverse A, then +, then B, and for
--  "X.P(Y)", we traverse X, then P, then Y. Syntactic = True means the
--  traversal follows the semantics, so the above are treated as if they were
--  "+"(A,B) and P(X,Y).

with A4G.Queries;

package Asis.Extensions.Iterator is

   subtype Structural_Queries is A4G.Queries.Structural_Queries;
   --  Enumeration of all structural queries -- that is, queries that take an
   --  Element and return its syntactic subelements

   subtype Query_Index is A4G.Queries.Query_Index;

   function Is_Leaf (E : Asis.Element) return Boolean;
   --  True if E has no subelements

   --  Tree traversals:

   generic

      type State_Information is limited private;

      with procedure Pre_Operation
                       (Q       :        Structural_Queries;
                        Index   :        Query_Index;
                        Is_List_Element : Boolean;
                        Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Post_Operation
                       (Q       :        Structural_Queries;
                        Index   :        Query_Index;
                        Is_List_Element : Boolean;
                        Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Pre_List_Operation
                       (Q       :        Structural_Queries;
                        List    : Asis.Element_List;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Post_List_Operation
                       (Q       :        Structural_Queries;
                        List    : Asis.Element_List;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

   procedure Traverse_Unit_Q
     (Unit          : Asis.Compilation_Unit;
      Control       : in out Traverse_Control;
      State         : in out State_Information;
      Traverse_Nils : Boolean;
      Syntactic     : Boolean);
   --  Traverses all the syntactical structure of the argument Compilation
   --  Unit. In ASIS, a Compilation Unit consists of context clause Elements
   --  and of the Element representing the program unit, and these syntax
   --  elements does not have a common root. Traverse_Unit instantiates
   --  Asis.Iterator.Traverse_Element passing its own formal parameters as
   --  actuals for Traverse_Element. Then it goes into all the
   --  first-depth-level structural components of the argument Compilation
   --  Unit by applying this instance of Traverse_Element to it.
   --
   --  If the value of traverse Control becomes Terminate_Immediately,
   --  traversing of all the unit components is terminated (that is, if it
   --  happens in some context clause Element, the Unit declaration Element
   --  will not be traversed.
   --
   --  Appropriate Unit_Kinds:
   --     A_Procedure
   --     A_Function
   --     A_Package
   --
   --     A_Generic_Procedure
   --     A_Generic_Function
   --     A_Generic_Package
   --
   --     A_Procedure_Instance
   --     A_Function_Instance
   --     A_Package_Instance
   --
   --     A_Procedure_Renaming
   --     A_Function_Renaming
   --     A_Package_Renaming
   --
   --     A_Generic_Procedure_Renaming
   --     A_Generic_Function_Renaming
   --     A_Generic_Package_Renaming
   --
   --     A_Procedure_Body
   --     A_Procedure_Body
   --     A_Function_Body
   --     A_Package_Body
   --
   --     A_Procedure_Body_Subunit
   --     A_Function_Body_Subunit
   --     A_Package_Body_Subunit
   --     A_Task_Body_Subunit
   --     A_Protected_Body_Subunit

   generic

      type State_Information is limited private;

      with procedure Pre_Operation
                       (Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Post_Operation
                       (Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

   procedure Traverse_Unit
     (Unit          : Asis.Compilation_Unit;
      Control       : in out Traverse_Control;
      State         : in out State_Information;
      Traverse_Nils : Boolean := False;
      Syntactic     : Boolean := True);
   --  Same as Traverse_Unit_Q above, except the Q parameter and the List
   --  operations are not present.

   generic

      type State_Information is limited private;

      with procedure Pre_Operation
                       (Q       :        Structural_Queries;
                        Index   :        Query_Index;
                        Is_List_Element : Boolean;
                        Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Post_Operation
                       (Q       :        Structural_Queries;
                        Index   :        Query_Index;
                        Is_List_Element : Boolean;
                        Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Pre_List_Operation
                       (Q       :        Structural_Queries;
                        List    : Asis.Element_List;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Post_List_Operation
                       (Q       :        Structural_Queries;
                        List    : Asis.Element_List;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

   procedure Traverse_Element_Q
     (Root_Query           : Structural_Queries;
      Root_Index           : Query_Index;
      Root_Is_List_Element : Boolean;
      Element              : Asis.Element;
      Control              : in out Traverse_Control;
      State                : in out State_Information;
      Traverse_Nils        : Boolean;
      Syntactic            : Boolean);
   --  This is the same as Asis.Iterator.Traverse_Element, except that the
   --  query that reached Element is passed in Q. Root_Query is passed to the
   --  outermost calls to Pre/Post_Operation.

   generic

      type State_Information is limited private;

      with procedure Pre_Operation
                       (Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

      with procedure Post_Operation
                       (Element :        Asis.Element;
                        Control : in out Traverse_Control;
                        State   : in out State_Information) is <>;

   procedure Traverse_Element
     (Element       : Asis.Element;
      Control       : in out Traverse_Control;
      State         : in out State_Information;
      Traverse_Nils : Boolean;
      Syntactic     : Boolean);
   --  This is the same as Traverse_Element in Asis.Iterator. See that package
   --  for detailed documentation.

end Asis.Extensions.Iterator;