Skip to content

Commit 2ebfd8f

Browse files
committed
pylint: Fix pylint error in frontend_cpp
Signed-off-by: Arthur Chan <[email protected]>
1 parent 93943dd commit 2ebfd8f

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

src/fuzz_introspector/frontends/frontend_cpp.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
#
1515
################################################################################
16+
"""Tree-sitter frontend for cpp."""
1617

1718
from typing import Any, Optional
1819

@@ -31,7 +32,8 @@ class CppSourceCodeFile(SourceCodeFile):
3132
"""Class for holding file-specific information."""
3233

3334
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."""
3537
self.func_defs: list['FunctionDefinition'] = []
3638
if self.source_content:
3739
# Initialization routines
@@ -84,7 +86,8 @@ def get_function_node(
8486
# Find the first instance of the function name
8587
for func in self.func_defs:
8688
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:
8891
return func
8992
else:
9093
if func.name == target_function_name:
@@ -146,7 +149,8 @@ def __init__(self, root: Node, tree_sitter_lang: Language,
146149

147150
def _extract_pointer_array_from_type(
148151
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."""
150154
# Count pointer
151155
pointer_count = 0
152156
while param_name.type == 'pointer_declarator':
@@ -235,7 +239,9 @@ def _extract_information(self):
235239

236240
# try:
237241
# 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()
239245
# except:
240246
# try:
241247
# full_name = full_name + self.root.child_by_field_name(
@@ -287,7 +293,8 @@ def _extract_information(self):
287293
pcount, acount, param_name = result
288294

289295
self.arg_types.append(
290-
f'{param_type.text.decode()}{"*" * pcount}{"[]" * acount}'
296+
f'{param_type.text.decode()}{"*" * pcount}'
297+
f'{"[]" * acount}'
291298
)
292299
self.arg_names.append(param_name.text.decode().replace(
293300
'&', ''))
@@ -414,7 +421,8 @@ def _process_field_expr_return_type(self, field_expr: Node,
414421
object_type = self.var_map.get(arg.text.decode())
415422
elif arg.type == 'call_expression':
416423
# 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);""
418426
# We give up here.
419427
logger.debug('Cant analyse this.')
420428
return ('', '')
@@ -459,15 +467,14 @@ def _process_callsites(self, stmt: Node,
459467
if var_type_obj is None:
460468
return []
461469

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']:
463471
logger.debug('Skipping.')
464472
return []
465473

466474
while True:
467475
if var_type_obj is None:
468476
return []
469477
if var_type_obj.type == 'qualified_identifier':
470-
# logger.debug('qualified idenfitier: %s', var_type_obj.text.decode())
471478
if var_type_obj.child_by_field_name('scope') is not None:
472479
var_type += var_type_obj.child_by_field_name(
473480
'scope').text.decode()
@@ -492,8 +499,8 @@ def _process_callsites(self, stmt: Node,
492499
var_type, var_name)
493500
# Handles implicit default constructor call
494501
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.
497504
cls = f'{var_type}::{var_type.rsplit("::")[-1]}'
498505
logger.debug('Trying to find class %s', cls)
499506
# added = False
@@ -505,8 +512,8 @@ def _process_callsites(self, stmt: Node,
505512
(cls, stmt.byte_range[1], stmt.start_point.row + 1))
506513
# if not added:
507514
# 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.
510517
# cls = var_type
511518
# if cls in project.all_functions:
512519
# logger.debug('Adding callsite')
@@ -545,7 +552,7 @@ def extract_callsites(self, project):
545552

546553
if not self.detailed_callsites:
547554
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'
549556
self.detailed_callsites.append({'Src': src_loc, 'Dst': dst})
550557

551558

@@ -563,6 +570,10 @@ def dump_module_logic(self,
563570
harness_source: str = '',
564571
dump_output=True):
565572
"""Dumps the data for the module in full."""
573+
_ = entry_function
574+
_ = harness_name
575+
_ = harness_source
576+
566577
logger.info('Dumping project-wide logic.')
567578
report: dict[str, Any] = {'report': 'name'}
568579
report['sources'] = []
@@ -649,6 +660,8 @@ def extract_calltree(self,
649660
line_number: int = -1,
650661
other_props: Optional[dict[str, Any]] = None) -> str:
651662
"""Extracts calltree string of a calltree so that FI core can use it."""
663+
_ = other_props
664+
652665
# Create calltree from a given function
653666
# Find the function in the source code
654667
logger.debug('Extracting calltree for %s', str(function))
@@ -725,6 +738,8 @@ def get_reachable_functions(
725738
function: Optional[str] = None,
726739
visited_functions: Optional[set[str]] = None) -> set[str]:
727740
"""Gets the reachable frunctions from a given function."""
741+
_ = source_file
742+
728743
# Create calltree from a given function
729744
# Find the function in the source code
730745
if not visited_functions:
@@ -770,6 +785,7 @@ def get_reachable_functions(
770785

771786
def find_function_from_approximate_name(
772787
self, function_name: str) -> Optional['FunctionDefinition']:
788+
"""Locate a function element with name approximately."""
773789
function_names = []
774790
for func in self.all_functions:
775791
if func.name == function_name:
@@ -833,7 +849,7 @@ def calculate_function_uses(self, target_name: str) -> int:
833849
if callsite[0] == target_name:
834850
found = True
835851
break
836-
elif callsite[0].endswith(target_name):
852+
if callsite[0].endswith(target_name):
837853
found = True
838854
break
839855
if found:
@@ -875,7 +891,8 @@ def _recursive_function_depth(function: FunctionDefinition) -> int:
875891

876892

877893
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."""
879896
results = []
880897

881898
for code_file in source_files:

0 commit comments

Comments
 (0)