Skip to content

Commit c35b9e2

Browse files
committed
feat: add merge method for TypeDef
1 parent 0bbb6b1 commit c35b9e2

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/dwarf2cpp/models.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Attribute(Object):
5959
bit_size: int | None = None
6060
is_static: bool = False
6161

62-
def merge(self, other: "Object") -> bool:
62+
def merge(self, other: Object) -> bool:
6363
if not isinstance(other, Attribute):
6464
return False
6565

@@ -101,7 +101,7 @@ class Function(Object):
101101
is_const: bool = False
102102
virtuality: VirtualityAttribute | None = None
103103

104-
def merge(self, other: "Function") -> bool:
104+
def merge(self, other: Object) -> bool:
105105
if not isinstance(other, Function):
106106
return False
107107

@@ -133,7 +133,7 @@ class Struct(Object):
133133
members: dict[int, list[Object]] = field(default_factory=lambda: defaultdict(list))
134134
alignment: int | None = None
135135

136-
def merge(self, other: "Struct") -> bool:
136+
def merge(self, other: Object) -> bool:
137137
if not isinstance(other, Struct):
138138
return False
139139

@@ -187,6 +187,23 @@ class TypeDef(Object):
187187
value: str | Struct | Class | Union | Enum | None = None
188188
alignment: int | None = None
189189

190+
def merge(self, other: Object) -> bool:
191+
if not isinstance(other, TypeDef):
192+
return False
193+
194+
if self.kind != other.kind or self.name != other.name or type(self.value) != type(other.value):
195+
return False
196+
197+
if isinstance(self.value, str):
198+
if self.value != other.value:
199+
return False
200+
else:
201+
if not self.value.merge(other.value):
202+
return False
203+
204+
self.alignment = self.alignment or other.alignment
205+
return True
206+
190207

191208
class TemplateParameterKind(enum.StrEnum):
192209
CONSTANT = "constant"
@@ -239,7 +256,7 @@ class Template(Object):
239256
declaration: Struct | Attribute | None = None
240257
parameters: list[TemplateParameter] = field(default_factory=list)
241258

242-
def merge(self, other: "Template") -> bool:
259+
def merge(self, other: Object) -> bool:
243260
if not isinstance(other, Template):
244261
return False
245262

0 commit comments

Comments
 (0)