Skip to content

Commit

Permalink
Fix hash for complex types
Browse files Browse the repository at this point in the history
  • Loading branch information
rihi committed Sep 4, 2024
1 parent 8ce78d3 commit 8676ccc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions decompiler/structures/pseudo/complextypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def declaration(self) -> str:
members = ";\n\t".join(self.members[k].declaration() for k in sorted(self.members.keys())) + ";"
return f"{self.type_specifier.value} {self.name} {{\n\t{members}\n}}"

def __hash__(self) -> int:
# Because dict is not hashable, we need our own hash implementation
return hash(repr(self))


@dataclass(frozen=True, order=True)
class Struct(_BaseStruct):
Expand Down Expand Up @@ -117,6 +121,10 @@ def get_member_name_by_type(self, _type: Type) -> str:
logging.warning(f"Cannot get member name for union {self}")
return "unknown_field"

def __hash__(self) -> int:
# Because list is not hashable, we need our own hash implementation
return hash(repr(self))


@dataclass(frozen=True, order=True)
class Enum(ComplexType):
Expand All @@ -134,6 +142,10 @@ def declaration(self) -> str:
members = ",\n\t".join(f"{x.name} = {x.value}" for x in self.members.values())
return f"{self.type_specifier.value} {self.name} {{\n\t{members}\n}}"

def __hash__(self) -> int:
# Because dict is not hashable, we need our own hash implementation
return hash(repr(self))


@dataclass(frozen=True, order=True)
class ComplexTypeName(Type):
Expand Down

0 comments on commit 8676ccc

Please sign in to comment.