Skip to content

Commit

Permalink
fix namespacing
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski committed Jan 16, 2025
1 parent 587c728 commit 9c2f08b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/fuzz_introspector/frontends/frontend_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,7 @@ def _extract_information(self):

# Handles class or namespace in the function name
if '::' in self.name:
prefix, _ = self.name.rsplit('::', 1)
if self.namespace_or_class and prefix:
self.namespace_or_class += f'::{prefix}'
else:
self.namespace_or_class = prefix
self.namespace_or_class, _ = self.name.rsplit('::', 1)

# Handles return type
type_node = self.root.child_by_field_name('type')
Expand Down Expand Up @@ -361,6 +357,8 @@ def _traverse_node_instr_count(node: Node) -> int:
def _process_invoke(self, expr: Node,
project) -> list[tuple[str, int, int]]:
"""Internal helper for processing the function invocation statement."""
logger.debug('Handling invoke statmenet: %s', expr.text.decode())
logger.debug('Current namespace: %s', self.namespace_or_class)
callsites = []
target_name: str = ''

Expand All @@ -380,7 +378,8 @@ def _process_invoke(self, expr: Node,
# Find the matching function in our project
logger.debug('Matching function %s', target_name)
matched_func = get_function_node(target_name,
project.all_functions)
project.all_functions,
self.namespace_or_class)
if matched_func:
logger.debug('Matched function: %s', matched_func.name)
target_name = matched_func.name
Expand Down Expand Up @@ -947,10 +946,10 @@ def analyse_source_code(source_content: str) -> SourceCodeFile:
return source_code


def get_function_node(
target_name: str,
function_list: List[FunctionDefinition],
one_layer_only: bool = False) -> Optional[FunctionDefinition]:
def get_function_node(target_name: str,
function_list: List[FunctionDefinition],
one_layer_only: bool = False,
namespace: str = '') -> Optional[FunctionDefinition]:
"""Helper to retrieve the RustFunction object of a function."""

logger.debug('Finding match for %s', target_name)
Expand All @@ -959,6 +958,13 @@ def get_function_node(
logger.debug('Found exact match')
return function

if namespace:
logger.debug('Finding function within namespace %s', namespace)
for function in function_list:
if namespace + '::' + target_name == function.name:
logger.debug('Found namespace match')
return function

# Exact match
# if target_name in function_map:
# return function_map[target_name]
Expand Down

0 comments on commit 9c2f08b

Please sign in to comment.