Skip to content

Commit

Permalink
Deep copy of ast nodes (#408)
Browse files Browse the repository at this point in the history
* update copy of ast nodes

* minor fix

---------

Co-authored-by: Steffen Enders <[email protected]>
  • Loading branch information
ebehner and steffenenders committed Jun 19, 2024
1 parent 800a3c1 commit 1e9c13c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions decompiler/structures/ast/ast_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def is_empty(self) -> bool:

def copy(self) -> VirtualRootNode:
"""Return a copy of the ast node."""
return VirtualRootNode(self.reaching_condition)
return VirtualRootNode(self.reaching_condition.copy())

def accept(self, visitor: ASTVisitorInterface[T]) -> T:
return visitor.visit_root_node(self)
Expand All @@ -288,7 +288,7 @@ def __repr__(self) -> str:

def copy(self) -> SeqNode:
"""Return a copy of the ast node."""
return SeqNode(self.reaching_condition)
return SeqNode(self.reaching_condition.copy())

@property
def children(self) -> Tuple[AbstractSyntaxTreeNode, ...]:
Expand Down Expand Up @@ -375,7 +375,7 @@ def __repr__(self) -> str:

def copy(self) -> CodeNode:
"""Return a copy of the ast node."""
return CodeNode(self.instructions.copy(), self.reaching_condition)
return CodeNode([i.copy() for i in self.instructions], self.reaching_condition.copy())

@property
def children(self) -> Tuple[AbstractSyntaxTreeNode, ...]:
Expand Down Expand Up @@ -508,7 +508,7 @@ def __repr__(self) -> str:

def copy(self) -> ConditionNode:
"""Return a copy of the ast node."""
return ConditionNode(self.condition, self.reaching_condition)
return ConditionNode(self.condition.copy(), self.reaching_condition.copy())

@property
def children(self) -> Tuple[Union[TrueNode, FalseNode], ...]:
Expand Down Expand Up @@ -655,7 +655,7 @@ def __repr__(self) -> str:

def copy(self) -> TrueNode:
"""Return a copy of the ast node."""
return TrueNode(self.reaching_condition)
return TrueNode(self.reaching_condition.copy())

@property
def branch_condition(self) -> LogicCondition:
Expand All @@ -680,7 +680,7 @@ def __repr__(self) -> str:

def copy(self) -> FalseNode:
"""Return a copy of the ast node."""
return FalseNode(self.reaching_condition)
return FalseNode(self.reaching_condition.copy())

@property
def branch_condition(self) -> LogicCondition:
Expand Down Expand Up @@ -810,7 +810,7 @@ class WhileLoopNode(LoopNode):

def copy(self) -> WhileLoopNode:
"""Return a copy of the ast node."""
return WhileLoopNode(self.condition, self.reaching_condition)
return WhileLoopNode(self.condition.copy(), self.reaching_condition.copy())

@property
def loop_type(self) -> LoopType:
Expand All @@ -837,7 +837,7 @@ class DoWhileLoopNode(LoopNode):

def copy(self) -> DoWhileLoopNode:
"""Return a copy of the ast node."""
return DoWhileLoopNode(self.condition, self.reaching_condition)
return DoWhileLoopNode(self.condition.copy(), self.reaching_condition.copy())

@property
def loop_type(self) -> LoopType:
Expand Down Expand Up @@ -882,7 +882,7 @@ def __str__(self) -> str:

def copy(self) -> ForLoopNode:
"""Return a copy of the ast node."""
return ForLoopNode(self.declaration, self.condition, self.modification, self.reaching_condition)
return ForLoopNode(self.declaration.copy(), self.condition.copy(), self.modification.copy(), self.reaching_condition.copy())

@property
def loop_type(self) -> LoopType:
Expand Down Expand Up @@ -950,7 +950,7 @@ def __repr__(self) -> str:

def copy(self) -> SwitchNode:
"""Return a copy of the ast node."""
return SwitchNode(self.expression, self.reaching_condition)
return SwitchNode(self.expression.copy(), self.reaching_condition.copy())

@property
def children(self) -> Tuple[CaseNode]:
Expand Down Expand Up @@ -1084,7 +1084,7 @@ def __repr__(self) -> str:

def copy(self) -> CaseNode:
"""Return a copy of the ast node."""
return CaseNode(self.expression, self.constant, self.reaching_condition, self.break_case)
return CaseNode(self.expression.copy(), self.constant.copy(), self.reaching_condition.copy(), self.break_case)

@property
def does_end_with_break(self) -> bool:
Expand Down

0 comments on commit 1e9c13c

Please sign in to comment.