Skip to content

Commit 3346fbb

Browse files
committed
feat(visitor): enhance type unit handling
1 parent 218f4c8 commit 3346fbb

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

src/dwarf2cpp/visitor.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def __init__(self, context: DWARFContext, base_dir: str):
6565
self._functions: dict[str, list[Function]] = defaultdict(list)
6666
self._templates: dict[str | int, dict[int, list[Template]]] = defaultdict(lambda: defaultdict(list))
6767
self._types = {}
68-
self._visited_type_units = set()
6968

7069
@property
7170
def files(self) -> Generator[tuple[str, dict[int, list[Object]]], None, None]:
@@ -76,6 +75,15 @@ def files(self) -> Generator[tuple[str, dict[int, list[Object]]], None, None]:
7675
Returns:
7776
List of files
7877
"""
78+
for i, tu in tqdm(
79+
enumerate(self.context.types_section_units),
80+
desc="Visiting type units",
81+
total=self.context.num_type_units,
82+
bar_format="[{n_fmt}/{total_fmt}] {desc} [{elapsed}, {rate_fmt}]",
83+
):
84+
tu_die = tu.unit_die
85+
self.visit(tu_die)
86+
7987
for i, cu in (
8088
pbar := tqdm(
8189
enumerate(self.context.compile_units),
@@ -958,20 +966,6 @@ def _set(self, die: DWARFDie, obj) -> None:
958966
def _resolve_type(self, die: DWARFDie, split=False) -> str | tuple[str, str]:
959967
die = die.resolve_type_unit_reference()
960968

961-
# resolve and visit type unit if needed
962-
t = die
963-
while True:
964-
if t.unit.is_type_unit:
965-
tu_die = t.unit.unit_die
966-
if tu_die.offset not in self._visited_type_units:
967-
self._visited_type_units.add(tu_die.offset)
968-
self.visit(tu_die)
969-
970-
if ty := t.find("DW_AT_type"):
971-
t = ty.as_referenced_die().resolve_type_unit_reference()
972-
else:
973-
break
974-
975969
key = (die.unit.is_type_unit, die.offset, split)
976970
if key in self._types:
977971
return self._types[key]

0 commit comments

Comments
 (0)