Skip to content

Commit

Permalink
Removed subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
fnhartmann committed Mar 11, 2024
1 parent 959565c commit f822dfd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions decompiler/pipeline/preprocessing/find_function_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from decompiler.pipeline.stage import PipelineStage
from decompiler.structures.pseudo.instructions import Assignment, Variable
from decompiler.structures.pseudo.operations import Call
from decompiler.structures.pseudo.typing import FunctionPointer, Pointer
from decompiler.structures.pseudo.typing import FunctionTypeDef, Pointer
from decompiler.task import DecompilerTask


Expand All @@ -25,7 +25,7 @@ def run(self, task: DecompilerTask):
and isinstance(expression.value.function, Variable)
):
expression.value.function._type = Pointer(
basetype=FunctionPointer(
basetype=FunctionTypeDef(
size=expression.value.function.type.size,
return_type=expression.value.function.type,
parameters=tuple(expression.value.parameters),
Expand Down
5 changes: 0 additions & 5 deletions decompiler/structures/pseudo/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ def __str__(self) -> str:
return f"{self.return_type}({', '.join(str(x) for x in self.parameters)})"


@dataclass(frozen=True, order=True)
class FunctionPointer(FunctionTypeDef):
pass


class TypeParser:
"""A type parser in charge of creating types."""

Expand Down
6 changes: 1 addition & 5 deletions tests/backend/test_codegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
OperationType,
UnaryOperation,
)
from decompiler.structures.pseudo.typing import CustomType, Float, FunctionPointer, Integer, Pointer, Type
from decompiler.structures.pseudo.typing import CustomType, Float, Integer, Pointer, Type
from decompiler.task import DecompilerTask
from decompiler.util.options import Options

Expand Down Expand Up @@ -80,8 +80,6 @@ def logic_cond(name: str, context) -> LogicCondition:
var_p = Variable("p", Pointer(int32))
var_fun_p = Variable("p", Pointer(FunctionTypeDef(0, int32, (int32,))))
var_fun_p0 = Variable("p0", Pointer(FunctionTypeDef(0, int32, (int32,))))
var_fun_ptr = Variable("ptr", Pointer(FunctionPointer(0, int32, (int32,))))
var_fun_ptr0 = Variable("ptr0", Pointer(FunctionPointer(0, int32, (int32,))))

const_0 = Constant(0, int32)
const_1 = Constant(1, int32)
Expand Down Expand Up @@ -1288,8 +1286,6 @@ class TestLocalDeclarationGenerator:
(1, [var_x.copy(), var_y.copy(), var_p.copy()], "int x;\nint y;\nint * p;"),
(1, [var_x.copy(), var_y.copy(), var_fun_p.copy()], "int x;\nint y;\nint (* p)(int);"),
(2, [var_x.copy(), var_y.copy(), var_fun_p.copy(), var_fun_p0.copy()], "int x, y;\nint (* p)(int), (* p0)(int);"),
(1, [var_x.copy(), var_y.copy(), var_fun_ptr.copy()], "int x;\nint y;\nint (* ptr)(int);"),
(2, [var_x.copy(), var_y.copy(), var_fun_ptr.copy(), var_fun_ptr0.copy()], "int x, y;\nint (* ptr)(int), (* ptr0)(int);"),
],
)
def test_variable_declaration(self, vars_per_line: int, variables: List[Variable], expected: str):
Expand Down
12 changes: 6 additions & 6 deletions tests/pipeline/preprocessing/test_find_function_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
Variable,
)
from decompiler.structures.pseudo.instructions import Branch, Return
from decompiler.structures.pseudo.typing import FunctionPointer, Pointer
from decompiler.structures.pseudo.typing import FunctionTypeDef, Pointer
from decompiler.task import DecompilerTask


def test_set_variable_to_function_pointer():
"""
Test the change of a variable type to FunctionPointer if there is a call on this variable.
Test the change of a variable type to function pointer if there is a call on this variable.
a = 0x0804c020
b = 1
Expand All @@ -40,12 +40,12 @@ def test_set_variable_to_function_pointer():
)
cfg.add_edges_from([UnconditionalEdge(n0, n1), TrueCase(n1, n2), FalseCase(n1, n3)])
FindFunctionPointer().run(DecompilerTask("test", cfg))
assert var_a.type == Pointer(FunctionPointer(32, Integer.int32_t(), ()))
assert var_a.type == Pointer(FunctionTypeDef(32, Integer.int32_t(), ()))


def test_set_variable_to_function_pointer_with_parameters():
"""
Test the change of a variable type to FunctionPointer if there is a call on this variable with parameters.
Test the change of a variable type to function pointer if there is a call on this variable with parameters.
a = 0x0804c020
b = 1
Expand All @@ -69,12 +69,12 @@ def test_set_variable_to_function_pointer_with_parameters():
)
cfg.add_edges_from([UnconditionalEdge(n0, n1), TrueCase(n1, n2), FalseCase(n1, n3)])
FindFunctionPointer().run(DecompilerTask("test", cfg))
assert var_a.type == Pointer(FunctionPointer(32, Integer.int32_t(), (var_c, var_d)))
assert var_a.type == Pointer(FunctionTypeDef(32, Integer.int32_t(), (var_c, var_d)))


def test_skip_set_variable_to_function_pointer():
"""
Test the skip of a change of a variable type to FunctionPointer if there is a call without a variable.
Test the skip of a change of a variable type to function pointer if there is a call without a variable.
a = 0x0804c020
b = 1
Expand Down

0 comments on commit f822dfd

Please sign in to comment.