Skip to content

Commit fae8447

Browse files
committed
refactor: improve function parameter name sync for constructors
1 parent a1fe919 commit fae8447

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/dwarf2cpp/visitor.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,22 @@ def visit_subprogram(self, die: DWARFDie) -> None:
455455
case _:
456456
raise ValueError(f"Unhandled child tag {child.tag}")
457457

458-
if die.linkage_name or die.short_name:
459-
key = f"{die.linkage_name or die.short_name}@{len(function.parameters)}"
458+
# sync parameter names from definition to declaration
459+
key = None
460+
if die.linkage_name:
461+
# c++ functions with external linkage
462+
key = f"{die.linkage_name}@{len(function.parameters)}"
463+
elif die.find("DW_AT_external") and die.short_name:
464+
# c functions with external linkage
465+
key = f"{die.short_name}@{len(function.parameters)}"
466+
467+
if key:
460468
self._functions[key].append(function)
469+
# if this is a definition of a class constructor, it has a DW_AT_specification pointing to the
470+
# declaration with no DW_AT_linkage_name. Since we know the relationship, we can manually add the
471+
# declaration to the function map
472+
if spec and not spec.linkage_name:
473+
self._functions[key].append(self._cache[spec.offset])
461474

462475
if key not in self._param_names:
463476
self._param_names[key] = [p.name for p in function.parameters]

0 commit comments

Comments
 (0)