From f822dfd650c768e2826275e8dccdc2bf4c3a4d06 Mon Sep 17 00:00:00 2001 From: fnhartmann Date: Mon, 11 Mar 2024 11:20:58 +0100 Subject: [PATCH] Removed subclassing --- .../pipeline/preprocessing/find_function_pointer.py | 4 ++-- decompiler/structures/pseudo/typing.py | 5 ----- tests/backend/test_codegenerator.py | 6 +----- .../preprocessing/test_find_function_pointer.py | 12 ++++++------ 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/decompiler/pipeline/preprocessing/find_function_pointer.py b/decompiler/pipeline/preprocessing/find_function_pointer.py index b76ccee38..7de378d3b 100644 --- a/decompiler/pipeline/preprocessing/find_function_pointer.py +++ b/decompiler/pipeline/preprocessing/find_function_pointer.py @@ -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 @@ -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), diff --git a/decompiler/structures/pseudo/typing.py b/decompiler/structures/pseudo/typing.py index aff8d5aca..f27086bcc 100644 --- a/decompiler/structures/pseudo/typing.py +++ b/decompiler/structures/pseudo/typing.py @@ -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.""" diff --git a/tests/backend/test_codegenerator.py b/tests/backend/test_codegenerator.py index 4faafb520..021160101 100644 --- a/tests/backend/test_codegenerator.py +++ b/tests/backend/test_codegenerator.py @@ -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 @@ -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) @@ -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): diff --git a/tests/pipeline/preprocessing/test_find_function_pointer.py b/tests/pipeline/preprocessing/test_find_function_pointer.py index c39fea290..a56af525e 100644 --- a/tests/pipeline/preprocessing/test_find_function_pointer.py +++ b/tests/pipeline/preprocessing/test_find_function_pointer.py @@ -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 @@ -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 @@ -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