@@ -78,21 +78,24 @@ package body Instrument.C_Utils is
7878 return Cursor_Is_Null (N);
7979 end Is_Null ;
8080
81- pragma Warnings (Off);
82-
8381 -- ------------------
8482 -- Visit_Children --
8583 -- ------------------
8684
8785 procedure Visit_Children
88- (Parent : Cursor_T;
89- Visitor : Cursor_Visitor_Function) is
90-
86+ (Parent : Cursor_T; Visitor : Cursor_Visitor_Function)
87+ is
9188 function Visitor_Wrapper
9289 (Node : Cursor_T;
9390 Parent : Cursor_T;
9491 Client_Data : Client_Data_T) return Child_Visit_Result_T
9592 with Convention => C;
93+ -- Callback for Clang.Index.Visit_Children. Just a wrapper around
94+ -- Visitor.
95+
96+ -- -------------------
97+ -- Visitor_Wrapper --
98+ -- -------------------
9699
97100 function Visitor_Wrapper
98101 (Node : Cursor_T;
@@ -104,24 +107,33 @@ package body Instrument.C_Utils is
104107 return Visitor (Node);
105108 end Visitor_Wrapper ;
106109
107- Data : Client_Data_T;
108- Result : unsigned;
110+ Dummy : constant unsigned := Visit_Children
111+ (Parent,
112+ Visitor_Wrapper'Unrestricted_Access,
113+ Client_Data_T (System.Null_Address));
114+
115+ -- Start of processing for Visit_Children
116+
109117 begin
110- Result :=
111- Visit_Children (Parent, Visitor_Wrapper'Unrestricted_Access, Data);
118+ null ;
112119 end Visit_Children ;
113120
114121 -- ---------
115122 -- Visit --
116123 -- ---------
117124
118125 procedure Visit (Parent : Cursor_T; Visitor : Cursor_Visitor_Function) is
119-
120126 function Visitor_Wrapper
121127 (Node : Cursor_T;
122128 Parent : Cursor_T;
123129 Client_Data : Client_Data_T) return Child_Visit_Result_T
124130 with Convention => C;
131+ -- Callback for Clang.Index.Visit_Children. Just a wrapper around
132+ -- Visitor.
133+
134+ -- -------------------
135+ -- Visitor_Wrapper --
136+ -- -------------------
125137
126138 function Visitor_Wrapper
127139 (Node : Cursor_T;
@@ -133,34 +145,41 @@ package body Instrument.C_Utils is
133145 return Visitor (Node);
134146 end Visitor_Wrapper ;
135147
136- Data : Client_Data_T;
137- Result : unsigned;
148+ Dummy : constant unsigned := Visit
149+ (Parent,
150+ Visitor_Wrapper'Unrestricted_Access,
151+ Client_Data_T (System.Null_Address));
152+
153+ -- Start of processing for Visit
154+
138155 begin
139- Result := Visit (Parent, Visitor_Wrapper'Unrestricted_Access, Data) ;
156+ null ;
140157 end Visit ;
141- pragma Warnings (On);
142158
143159 -- ----------------
144160 -- Get_Children --
145161 -- ----------------
146162
147163 function Get_Children (N : Cursor_T) return Cursor_Vectors.Vector is
148-
149164 Res : Vector;
150165
151- -- Append the children to the result vector and continue the traversal
152- -- until all children have been appended.
153-
154166 function Append_Child (Cursor : Cursor_T) return Child_Visit_Result_T
155167 with Convention => C;
168+ -- Callback for Visit_Children. Append Cursor to Res and continue the
169+ -- traversal.
156170
157- function Append_Child (Cursor : Cursor_T) return Child_Visit_Result_T
158- is
171+ -- ----------------
172+ -- Append_Child --
173+ -- ----------------
174+
175+ function Append_Child (Cursor : Cursor_T) return Child_Visit_Result_T is
159176 begin
160177 Res.Append (Cursor);
161178 return Child_Visit_Continue;
162179 end Append_Child ;
163180
181+ -- Start of processing for Get_Children
182+
164183 begin
165184 Visit_Children (N, Get_Children.Append_Child'Unrestricted_Access);
166185 return Res;
@@ -190,6 +209,9 @@ package body Instrument.C_Utils is
190209 end if ;
191210 return Child_Visit_Recurse;
192211 end Process ;
212+
213+ -- Start of processing for Get_Lambda_Exprs
214+
193215 begin
194216 Visit_Children (N, Process'Unrestricted_Access);
195217 return Res;
@@ -223,6 +245,10 @@ package body Instrument.C_Utils is
223245 end ;
224246 end Is_Unit_Of_Interest ;
225247
248+ -- -------------
249+ -- To_Vector --
250+ -- -------------
251+
226252 function To_Vector (N : Cursor_T) return Cursor_Vectors.Vector is
227253 Res : Cursor_Vectors.Vector;
228254 begin
@@ -235,28 +261,36 @@ package body Instrument.C_Utils is
235261 -- ------------
236262
237263 function Get_Main (TU : Translation_Unit_T) return Cursor_T is
238-
239- Main_Decl_Cursor : Cursor_T := Get_Null_Cursor;
264+ Result : Cursor_T := Get_Null_Cursor;
240265
241266 function Visit_Decl (Cursor : Cursor_T) return Child_Visit_Result_T
242267 with Convention => C;
268+ -- Callback for Visit_Children. Set Result and break the iteration if
269+ -- Cursor is the "main" function definition, continue the iteration to
270+ -- find the main otherwise.
243271
244- function Visit_Decl (Cursor : Cursor_T) return Child_Visit_Result_T
245- is
272+ -- --------------
273+ -- Visit_Decl --
274+ -- --------------
275+
276+ function Visit_Decl (Cursor : Cursor_T) return Child_Visit_Result_T is
246277 begin
247278 if Kind (Cursor) = Cursor_Translation_Unit then
248279 return Child_Visit_Recurse;
249280 end if ;
250281 if Cursor_Get_Mangling (Cursor) = " main" then
251- Main_Decl_Cursor := Cursor;
282+ Result := Cursor;
252283 return Child_Visit_Break;
253284 end if ;
254285 return Child_Visit_Continue;
255286 end Visit_Decl ;
287+
288+ -- Start of processing for Get_Main
289+
256290 begin
257291 Visit_Children (Parent => Get_Translation_Unit_Cursor (TU),
258292 Visitor => Visit_Decl'Unrestricted_Access);
259- return Main_Decl_Cursor ;
293+ return Result ;
260294 end Get_Main ;
261295
262296 -- Rewriting utilities
@@ -268,20 +302,23 @@ package body Instrument.C_Utils is
268302 procedure Add_Statement_In_Main
269303 (TU : Translation_Unit_T;
270304 Rew : Rewriter_T;
271- Statement : String) is
272-
305+ Statement : String)
306+ is
273307 function Visit_Decl (Cursor : Cursor_T) return Child_Visit_Result_T
274308 with Convention => C;
275309 -- Traverse the tree until the main function is found, and insert a
276310 -- statement.
277311
278- function Visit_Decl (Cursor : Cursor_T) return Child_Visit_Result_T
279- is
312+ -- --------------
313+ -- Visit_Decl --
314+ -- --------------
315+
316+ function Visit_Decl (Cursor : Cursor_T) return Child_Visit_Result_T is
280317 begin
281318 if Kind (Cursor) = Cursor_Translation_Unit then
282319 return Child_Visit_Recurse;
283- end if ;
284- if Cursor_Get_Mangling (Cursor) = " main" then
320+
321+ elsif Cursor_Get_Mangling (Cursor) = " main" then
285322 declare
286323 Fun_Children : constant Vector := Get_Children (Cursor);
287324 Body_Cursor : constant Cursor_T :=
@@ -303,9 +340,14 @@ package body Instrument.C_Utils is
303340 Insert => Statement);
304341 end ;
305342 return Child_Visit_Break;
343+
344+ else
345+ return Child_Visit_Continue;
306346 end if ;
307- return Child_Visit_Continue;
308347 end Visit_Decl ;
348+
349+ -- Start of processing for Add_Statement_In_Main
350+
309351 begin
310352 Visit_Children (Parent => Get_Translation_Unit_Cursor (TU),
311353 Visitor => Visit_Decl'Unrestricted_Access);
@@ -443,6 +485,8 @@ package body Instrument.C_Utils is
443485
444486 procedure Print_Tokens (TU : Translation_Unit_T; N : Cursor_T) is
445487 procedure Put_Token (Tok : Token_T);
488+ -- Callback for Iterate_Tokens. Put the spelling of Tok on the standard
489+ -- output.
446490
447491 -- -------------
448492 -- Put_Token --
@@ -452,6 +496,9 @@ package body Instrument.C_Utils is
452496 begin
453497 Put (Get_Token_Spelling (TU, Tok));
454498 end Put_Token ;
499+
500+ -- Start of processing for Print_Tokens
501+
455502 begin
456503 Iterate_Tokens (TU, N, Put_Token'Access );
457504 New_Line;
0 commit comments