@@ -10,12 +10,14 @@ use gitql_core::values::null::NullValue;
1010use gitql_core:: values:: text:: TextValue ;
1111use gitql_engine:: data_provider:: DataProvider ;
1212
13- use crate :: clang_parser:: CompilationUnit ;
14- use crate :: visitor:: class;
15- use crate :: visitor:: enumeration;
16- use crate :: visitor:: function;
17- use crate :: visitor:: global;
18- use crate :: visitor:: unions;
13+ use crate :: clang_ql:: clang_parser:: CompilationUnit ;
14+ use crate :: clang_ql:: visitors:: class;
15+ use crate :: clang_ql:: visitors:: enumeration;
16+ use crate :: clang_ql:: visitors:: function;
17+ use crate :: clang_ql:: visitors:: global;
18+ use crate :: clang_ql:: visitors:: unions;
19+
20+ use super :: values:: SourceLocValue ;
1921
2022pub struct ClangDataProvider {
2123 pub compilation_units : Vec < CompilationUnit > ,
@@ -78,63 +80,48 @@ fn select_classes(
7880 for class in ast_classes. iter ( ) {
7981 let mut values: Vec < Box < dyn Value > > = Vec :: with_capacity ( selected_columns. len ( ) ) ;
8082
81- for field_name in selected_columns {
82- if field_name == "name" {
83+ for column_name in selected_columns {
84+ if column_name == "name" {
8385 values. push ( Box :: new ( TextValue :: new ( class. name . to_owned ( ) ) ) ) ;
8486 continue ;
8587 }
8688
87- if field_name == "bases_count" {
89+ if column_name == "bases_count" {
8890 values. push ( Box :: new ( IntValue :: new ( class. attributes . bases_count . into ( ) ) ) ) ;
8991 continue ;
9092 }
9193
92- if field_name == "methods_count" {
94+ if column_name == "methods_count" {
9395 values. push ( Box :: new ( IntValue :: new (
9496 class. attributes . methods_count . into ( ) ,
9597 ) ) ) ;
9698 continue ;
9799 }
98100
99- if field_name == "fields_count" {
101+ if column_name == "fields_count" {
100102 values. push ( Box :: new ( IntValue :: new (
101103 class. attributes . fields_count . into ( ) ,
102104 ) ) ) ;
103105 continue ;
104106 }
105107
106- if field_name == "is_struct" {
108+ if column_name == "is_struct" {
107109 values. push ( Box :: new ( BoolValue :: new ( class. is_struct ) ) ) ;
108110 continue ;
109111 }
110112
111- if field_name == "size" {
113+ if column_name == "size" {
112114 values. push ( Box :: new ( IntValue :: new ( class. size ) ) ) ;
113115 continue ;
114116 }
115117
116- if field_name == "align" {
118+ if column_name == "align" {
117119 values. push ( Box :: new ( IntValue :: new ( class. align ) ) ) ;
118120 continue ;
119121 }
120122
121- if field_name == "file" {
122- values. push ( Box :: new ( TextValue :: new ( class. location . file . to_string ( ) ) ) ) ;
123- continue ;
124- }
125-
126- if field_name == "line" {
127- values. push ( Box :: new ( IntValue :: new ( class. location . line . into ( ) ) ) ) ;
128- continue ;
129- }
130-
131- if field_name == "column" {
132- values. push ( Box :: new ( IntValue :: new ( class. location . column . into ( ) ) ) ) ;
133- continue ;
134- }
135-
136- if field_name == "offset" {
137- values. push ( Box :: new ( IntValue :: new ( class. location . offset . into ( ) ) ) ) ;
123+ if column_name == "source_loc" {
124+ values. push ( Box :: new ( SourceLocValue :: new ( class. location . clone ( ) ) ) ) ;
138125 continue ;
139126 }
140127
@@ -157,42 +144,26 @@ fn select_enums(
157144 for enumeration in ast_enums. iter ( ) {
158145 let mut values: Vec < Box < dyn Value > > = Vec :: with_capacity ( selected_columns. len ( ) ) ;
159146
160- for field_name in selected_columns {
161- if field_name == "name" {
147+ for column_name in selected_columns {
148+ if column_name == "name" {
162149 values. push ( Box :: new ( TextValue :: new ( enumeration. name . to_owned ( ) ) ) ) ;
163150 continue ;
164151 }
165152
166- if field_name == "constants_count" {
153+ if column_name == "constants_count" {
167154 let value = enumeration. attributes . constants_count . into ( ) ;
168155 values. push ( Box :: new ( IntValue :: new ( value) ) ) ;
169156 continue ;
170157 }
171158
172- if field_name == "type_literal" {
159+ if column_name == "type_literal" {
173160 let value = Box :: new ( TextValue :: new ( enumeration. type_literal . to_owned ( ) ) ) ;
174161 values. push ( value) ;
175162 continue ;
176163 }
177164
178- if field_name == "file" {
179- let value = Box :: new ( TextValue :: new ( enumeration. location . file . to_owned ( ) ) ) ;
180- values. push ( value) ;
181- continue ;
182- }
183-
184- if field_name == "line" {
185- values. push ( Box :: new ( IntValue :: new ( enumeration. location . line . into ( ) ) ) ) ;
186- continue ;
187- }
188-
189- if field_name == "column" {
190- values. push ( Box :: new ( IntValue :: new ( enumeration. location . column . into ( ) ) ) ) ;
191- continue ;
192- }
193-
194- if field_name == "offset" {
195- values. push ( Box :: new ( IntValue :: new ( enumeration. location . offset . into ( ) ) ) ) ;
165+ if column_name == "source_loc" {
166+ values. push ( Box :: new ( SourceLocValue :: new ( enumeration. location . clone ( ) ) ) ) ;
196167 continue ;
197168 }
198169
@@ -215,41 +186,25 @@ fn select_unions(
215186 for union_node in ast_unions. iter ( ) {
216187 let mut values: Vec < Box < dyn Value > > = Vec :: with_capacity ( selected_columns. len ( ) ) ;
217188
218- for field_name in selected_columns {
219- if field_name == "name" {
189+ for column_name in selected_columns {
190+ if column_name == "name" {
220191 values. push ( Box :: new ( TextValue :: new ( union_node. name . to_owned ( ) ) ) ) ;
221192 continue ;
222193 }
223194
224- if field_name == "fields_count" {
195+ if column_name == "fields_count" {
225196 let value = union_node. attributes . fields_count . into ( ) ;
226197 values. push ( Box :: new ( IntValue :: new ( value) ) ) ;
227198 continue ;
228199 }
229200
230- if field_name == "size" {
201+ if column_name == "size" {
231202 values. push ( Box :: new ( IntValue :: new ( union_node. size ) ) ) ;
232203 continue ;
233204 }
234205
235- if field_name == "file" {
236- let value = Box :: new ( TextValue :: new ( union_node. location . file . to_owned ( ) ) ) ;
237- values. push ( value) ;
238- continue ;
239- }
240-
241- if field_name == "line" {
242- values. push ( Box :: new ( IntValue :: new ( union_node. location . line . into ( ) ) ) ) ;
243- continue ;
244- }
245-
246- if field_name == "column" {
247- values. push ( Box :: new ( IntValue :: new ( union_node. location . column . into ( ) ) ) ) ;
248- continue ;
249- }
250-
251- if field_name == "offset" {
252- values. push ( Box :: new ( IntValue :: new ( union_node. location . offset . into ( ) ) ) ) ;
206+ if column_name == "source_loc" {
207+ values. push ( Box :: new ( SourceLocValue :: new ( union_node. location . clone ( ) ) ) ) ;
253208 continue ;
254209 }
255210
@@ -272,89 +227,74 @@ fn select_functions(
272227 for function in ast_functions. iter ( ) {
273228 let mut values: Vec < Box < dyn Value > > = Vec :: with_capacity ( selected_columns. len ( ) ) ;
274229
275- for field_name in selected_columns {
276- if field_name == "name" {
230+ for column_name in selected_columns {
231+ if column_name == "name" {
277232 values. push ( Box :: new ( TextValue :: new ( function. name . to_owned ( ) ) ) ) ;
278233 continue ;
279234 }
280235
281- if field_name == "signature" {
236+ if column_name == "signature" {
282237 values. push ( Box :: new ( TextValue :: new ( function. signature . to_owned ( ) ) ) ) ;
283238 continue ;
284239 }
285240
286- if field_name == "args_count" {
241+ if column_name == "args_count" {
287242 values. push ( Box :: new ( IntValue :: new ( function. arguments_count as i64 ) ) ) ;
288243 continue ;
289244 }
290245
291- if field_name == "class_name" {
246+ if column_name == "class_name" {
292247 values. push ( Box :: new ( TextValue :: new ( function. class_name . to_owned ( ) ) ) ) ;
293248 continue ;
294249 }
295250
296- if field_name == "return_type" {
251+ if column_name == "return_type" {
297252 values. push ( Box :: new ( TextValue :: new ( function. return_type . to_owned ( ) ) ) ) ;
298253 continue ;
299254 }
300255
301- if field_name == "is_method" {
256+ if column_name == "is_method" {
302257 values. push ( Box :: new ( BoolValue :: new ( function. is_method ) ) ) ;
303258 continue ;
304259 }
305260
306- if field_name == "is_virtual" {
261+ if column_name == "is_virtual" {
307262 values. push ( Box :: new ( BoolValue :: new ( function. is_virtual ) ) ) ;
308263 continue ;
309264 }
310265
311- if field_name == "is_pure_virtual" {
266+ if column_name == "is_pure_virtual" {
312267 values. push ( Box :: new ( BoolValue :: new ( function. is_pure_virtual ) ) ) ;
313268 continue ;
314269 }
315270
316- if field_name == "is_static" {
271+ if column_name == "is_static" {
317272 values. push ( Box :: new ( BoolValue :: new ( function. is_static ) ) ) ;
318273 continue ;
319274 }
320275
321- if field_name == "is_const" {
276+ if column_name == "is_const" {
322277 values. push ( Box :: new ( BoolValue :: new ( function. is_const ) ) ) ;
323278 continue ;
324279 }
325280
326- if field_name == "has_template" {
281+ if column_name == "has_template" {
327282 values. push ( Box :: new ( BoolValue :: new ( function. has_template ) ) ) ;
328283 continue ;
329284 }
330285
331- if field_name == "access_modifier" {
286+ if column_name == "access_modifier" {
332287 values. push ( Box :: new ( IntValue :: new ( function. access_modifier as i64 ) ) ) ;
333288 continue ;
334289 }
335290
336- if field_name == "is_variadic" {
291+ if column_name == "is_variadic" {
337292 values. push ( Box :: new ( BoolValue :: new ( function. is_variadic ) ) ) ;
338293 continue ;
339294 }
340295
341- if field_name == "file" {
342- values. push ( Box :: new ( TextValue :: new ( function. location . file . to_owned ( ) ) ) ) ;
343- continue ;
344- }
345-
346- if field_name == "line" {
347- values. push ( Box :: new ( IntValue :: new ( function. location . line . into ( ) ) ) ) ;
348- continue ;
349- }
350-
351- if field_name == "column" {
352- values. push ( Box :: new ( IntValue :: new ( function. location . column . into ( ) ) ) ) ;
353- continue ;
354- }
355-
356- if field_name == "offset" {
357- values. push ( Box :: new ( IntValue :: new ( function. location . offset . into ( ) ) ) ) ;
296+ if column_name == "source_loc" {
297+ values. push ( Box :: new ( SourceLocValue :: new ( function. location . clone ( ) ) ) ) ;
358298 continue ;
359299 }
360300
@@ -376,39 +316,25 @@ fn select_variables(
376316 let ast_variables = global:: select_clang_variables ( compilation_unit) ;
377317 for variable in ast_variables. iter ( ) {
378318 let mut values: Vec < Box < dyn Value > > = Vec :: with_capacity ( selected_columns. len ( ) ) ;
379- for field_name in selected_columns {
380- if field_name == "name" {
319+ for column_name in selected_columns {
320+ if column_name == "name" {
381321 values. push ( Box :: new ( TextValue :: new ( variable. name . to_owned ( ) ) ) ) ;
382322 continue ;
383323 }
384324
385- if field_name == "type" {
325+ if column_name == "type" {
386326 values. push ( Box :: new ( TextValue :: new ( variable. type_literal . to_owned ( ) ) ) ) ;
387327 continue ;
388328 }
389329
390- if field_name == "is_volatile" {
330+ if column_name == "is_volatile" {
391331 values. push ( Box :: new ( BoolValue :: new ( variable. is_volatile ) ) ) ;
392332 continue ;
393333 }
394334
395- if field_name == "file" {
396- values. push ( Box :: new ( TextValue :: new ( variable. location . file . to_string ( ) ) ) ) ;
397- continue ;
398- }
399-
400- if field_name == "line" {
401- values. push ( Box :: new ( IntValue :: new ( variable. location . line as i64 ) ) ) ;
402- continue ;
403- }
404-
405- if field_name == "column" {
406- values. push ( Box :: new ( IntValue :: new ( variable. location . column as i64 ) ) ) ;
407- continue ;
408- }
335+ if column_name == "source_loc" {
336+ values. push ( Box :: new ( SourceLocValue :: new ( variable. location . clone ( ) ) ) ) ;
409337
410- if field_name == "offset" {
411- values. push ( Box :: new ( IntValue :: new ( variable. location . offset as i64 ) ) ) ;
412338 continue ;
413339 }
414340
0 commit comments