13
13
# limitations under the License.
14
14
#
15
15
################################################################################
16
+ """Tree-sitter frontend for cpp."""
16
17
17
18
from typing import Any , Optional
18
19
@@ -31,7 +32,8 @@ class CppSourceCodeFile(SourceCodeFile):
31
32
"""Class for holding file-specific information."""
32
33
33
34
def language_specific_process (self ):
34
- """Function to perform some language specific processes in subclasses."""
35
+ """Function to perform some language specific processes in
36
+ subclasses."""
35
37
self .func_defs : list ['FunctionDefinition' ] = []
36
38
if self .source_content :
37
39
# Initialization routines
@@ -84,7 +86,8 @@ def get_function_node(
84
86
# Find the first instance of the function name
85
87
for func in self .func_defs :
86
88
if func .namespace_or_class :
87
- if func .namespace_or_class + '::' + func .name == target_function_name :
89
+ check_name = func .namespace_or_class + '::' + func .name
90
+ if check_name == target_function_name :
88
91
return func
89
92
else :
90
93
if func .name == target_function_name :
@@ -146,7 +149,8 @@ def __init__(self, root: Node, tree_sitter_lang: Language,
146
149
147
150
def _extract_pointer_array_from_type (
148
151
self , param_name : Node ) -> tuple [int , int , Node ]:
149
- """Extract the pointer, array count from type and return the pain type."""
152
+ """Extract the pointer, array count from type and return the
153
+ pain type."""
150
154
# Count pointer
151
155
pointer_count = 0
152
156
while param_name .type == 'pointer_declarator' :
@@ -235,7 +239,9 @@ def _extract_information(self):
235
239
236
240
# try:
237
241
# full_name = full_name + self.root.child_by_field_name(
238
- # 'declarator').child_by_field_name('declarator').child_by_field_name('declarator').text.decode()
242
+ # 'declarator').child_by_field_name(
243
+ # 'declarator').child_by_field_name(
244
+ # 'declarator').text.decode()
239
245
# except:
240
246
# try:
241
247
# full_name = full_name + self.root.child_by_field_name(
@@ -287,7 +293,8 @@ def _extract_information(self):
287
293
pcount , acount , param_name = result
288
294
289
295
self .arg_types .append (
290
- f'{ param_type .text .decode ()} { "*" * pcount } { "[]" * acount } '
296
+ f'{ param_type .text .decode ()} { "*" * pcount } '
297
+ f'{ "[]" * acount } '
291
298
)
292
299
self .arg_names .append (param_name .text .decode ().replace (
293
300
'&' , '' ))
@@ -414,7 +421,8 @@ def _process_field_expr_return_type(self, field_expr: Node,
414
421
object_type = self .var_map .get (arg .text .decode ())
415
422
elif arg .type == 'call_expression' :
416
423
# Bail, we do not support this yet. Examples of code:
417
- # "static_cast<impl::xpath_query_impl*>(_impl)->root->eval_string(c, sd.stack);""
424
+ # "static_cast<impl::xpath_query_impl*>(_impl)->root->eval_string
425
+ # (c, sd.stack);""
418
426
# We give up here.
419
427
logger .debug ('Cant analyse this.' )
420
428
return ('' , '' )
@@ -459,15 +467,14 @@ def _process_callsites(self, stmt: Node,
459
467
if var_type_obj is None :
460
468
return []
461
469
462
- if var_type_obj .type == 'primitive_type' or var_type_obj . type == 'sized_type_specifier' :
470
+ if var_type_obj .type in [ 'primitive_type' , 'sized_type_specifier' ] :
463
471
logger .debug ('Skipping.' )
464
472
return []
465
473
466
474
while True :
467
475
if var_type_obj is None :
468
476
return []
469
477
if var_type_obj .type == 'qualified_identifier' :
470
- # logger.debug('qualified idenfitier: %s', var_type_obj.text.decode())
471
478
if var_type_obj .child_by_field_name ('scope' ) is not None :
472
479
var_type += var_type_obj .child_by_field_name (
473
480
'scope' ).text .decode ()
@@ -492,8 +499,8 @@ def _process_callsites(self, stmt: Node,
492
499
var_type , var_name )
493
500
# Handles implicit default constructor call
494
501
if var_name .type == 'identifier' :
495
- # We're looking for a constructor, so add the name as it should be
496
- # the name of the constructor.
502
+ # We're looking for a constructor, so add the name as it
503
+ # should be the name of the constructor.
497
504
cls = f'{ var_type } ::{ var_type .rsplit ("::" )[- 1 ]} '
498
505
logger .debug ('Trying to find class %s' , cls )
499
506
# added = False
@@ -505,8 +512,8 @@ def _process_callsites(self, stmt: Node,
505
512
(cls , stmt .byte_range [1 ], stmt .start_point .row + 1 ))
506
513
# if not added:
507
514
# logger.debug('Trying a hacky match.')
508
- # # Hack to make sure we add in case our analysis of contructors was
509
- # # wrong. TODO(David) fix.
515
+ # # Hack to make sure we add in case our analysis of
516
+ # # constructors was wrong. TODO(David) fix.
510
517
# cls = var_type
511
518
# if cls in project.all_functions:
512
519
# logger.debug('Adding callsite')
@@ -545,7 +552,7 @@ def extract_callsites(self, project):
545
552
546
553
if not self .detailed_callsites :
547
554
for dst , src_line in self .base_callsites :
548
- src_loc = self .parent_source .source_file + ':%d ,1' % ( src_line )
555
+ src_loc = self .parent_source .source_file + f': { src_line } ,1'
549
556
self .detailed_callsites .append ({'Src' : src_loc , 'Dst' : dst })
550
557
551
558
@@ -563,6 +570,10 @@ def dump_module_logic(self,
563
570
harness_source : str = '' ,
564
571
dump_output = True ):
565
572
"""Dumps the data for the module in full."""
573
+ _ = entry_function
574
+ _ = harness_name
575
+ _ = harness_source
576
+
566
577
logger .info ('Dumping project-wide logic.' )
567
578
report : dict [str , Any ] = {'report' : 'name' }
568
579
report ['sources' ] = []
@@ -649,6 +660,8 @@ def extract_calltree(self,
649
660
line_number : int = - 1 ,
650
661
other_props : Optional [dict [str , Any ]] = None ) -> str :
651
662
"""Extracts calltree string of a calltree so that FI core can use it."""
663
+ _ = other_props
664
+
652
665
# Create calltree from a given function
653
666
# Find the function in the source code
654
667
logger .debug ('Extracting calltree for %s' , str (function ))
@@ -725,6 +738,8 @@ def get_reachable_functions(
725
738
function : Optional [str ] = None ,
726
739
visited_functions : Optional [set [str ]] = None ) -> set [str ]:
727
740
"""Gets the reachable frunctions from a given function."""
741
+ _ = source_file
742
+
728
743
# Create calltree from a given function
729
744
# Find the function in the source code
730
745
if not visited_functions :
@@ -770,6 +785,7 @@ def get_reachable_functions(
770
785
771
786
def find_function_from_approximate_name (
772
787
self , function_name : str ) -> Optional ['FunctionDefinition' ]:
788
+ """Locate a function element with name approximately."""
773
789
function_names = []
774
790
for func in self .all_functions :
775
791
if func .name == function_name :
@@ -833,7 +849,7 @@ def calculate_function_uses(self, target_name: str) -> int:
833
849
if callsite [0 ] == target_name :
834
850
found = True
835
851
break
836
- elif callsite [0 ].endswith (target_name ):
852
+ if callsite [0 ].endswith (target_name ):
837
853
found = True
838
854
break
839
855
if found :
@@ -875,7 +891,8 @@ def _recursive_function_depth(function: FunctionDefinition) -> int:
875
891
876
892
877
893
def load_treesitter_trees (source_files , is_log = True ) -> CppProject :
878
- """Creates treesitter trees for all files in a given list of source files."""
894
+ """Creates treesitter trees for all files in a given list of
895
+ source files."""
879
896
results = []
880
897
881
898
for code_file in source_files :
0 commit comments