Skip to content

Commit

Permalink
Merge branch 'main' into generalise-project-class
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
  • Loading branch information
arthurscchan authored Jan 17, 2025
2 parents 8721a15 + 82eb64a commit 0a23811
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions src/fuzz_introspector/frontends/frontend_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,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 @@ -363,6 +359,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 @@ -381,10 +379,12 @@ def _process_invoke(self, expr: Node,

# Find the matching function in our project
logger.debug('Matching function %s', target_name)
matched_func = project.find_function_from_approximate_name(
target_name)
matched_func = get_function_node(
target_name,
project.all_functions,
namespace=self.namespace_or_class)
if matched_func:
logger.debug('Matched function')
logger.debug('Matched function: %s', matched_func.name)
target_name = matched_func.name
else:
logger.debug('Did not find matching function')
Expand Down Expand Up @@ -944,10 +944,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 @@ -956,6 +956,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
2 changes: 1 addition & 1 deletion src/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "fuzz-introspector"
version = "0.1.6"
version = "0.1.7"
authors = [
{ name="David Korczynski", email="david@adalogics.com" },
]
Expand Down

0 comments on commit 0a23811

Please sign in to comment.