Skip to content

Commit

Permalink
Fix: ArrayType,config,tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoQuix committed Jun 12, 2024
1 parent 61ffa12 commit 17aa000
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Counter, List

from decompiler.pipeline.stage import PipelineStage
from decompiler.structures.pseudo import CustomType, Float, GlobalVariable, Integer, Pointer, Type, Variable
from decompiler.structures.pseudo import ArrayType, CustomType, Float, GlobalVariable, Integer, Pointer, Type, Variable
from decompiler.structures.visitors.ast_dataflowobjectvisitor import BaseAstDataflowObjectVisitor
from decompiler.structures.visitors.substitute_visitor import SubstituteVisitor
from decompiler.task import DecompilerTask
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self, task: DecompilerTask) -> None:
var_type = vars[0].type
name_identifier = self._get_name_identifier(variable_id.name)

counter_postfix = f"{self._counter_separator}{counter[(name_identifier, var_type)]}"
counter_postfix = f"{self._counter_separator}{counter[(name_identifier, var_type)]}" # array[0x12] != array[0x13] kriegt aber selben Namen, da Typen unterschiedlich sind
counter[(name_identifier, var_type)] += 1

prefix = self._hungarian_prefix(var_type)
Expand Down Expand Up @@ -112,17 +112,18 @@ def _get_name_identifier(self, name: str) -> str:
def _hungarian_prefix(self, var_type: Type) -> str | None:
"""Return hungarian prefix to a given variable type."""
match var_type:
case Pointer():
case Pointer() | ArrayType():
if self._pointer_base:
return f"{self._hungarian_prefix(var_type.type)}p"
pprefix = self._hungarian_prefix(var_type.type)
return f"{pprefix}p" if pprefix is not None else "unkp"
else:
return "p"
case CustomType():
if var_type.is_boolean:
return "b"
elif var_type.size == 0:
if var_type.size == 0:
return "v"
case _ if isinstance(var_type, Integer | Float):
case Integer() | Float():
sign = "u" if isinstance(var_type, Integer) and not var_type.is_signed else ""
prefix = self.type_prefix[type(var_type)].get(var_type.size, "unk")
return f"{sign}{prefix}"
Expand Down
10 changes: 0 additions & 10 deletions decompiler/util/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,6 @@
"is_hidden_from_cli": false,
"argument_name": "--for-loop-exclude-conditions"
},
{
"dest": "readability-based-refinement.rename_while_loop_variables",
"default": true,
"type": "boolean",
"title": "Rename while-loop variables",
"description": "Rename while-loop counter variables to counter, counter1, ...",
"is_hidden_from_gui": false,
"is_hidden_from_cli": false,
"argument_name": "--rename-while-loop-variables"
},
{
"dest": "variable-name-generation.notation",
"default": "system_hungarian",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ def test_different_custom_names_1():
)
ast = AbstractSyntaxTree(node, {})
_run_vng(ast, _generate_options())
assert node.instructions[0].destination.name == "dLoopBreak0"
assert node.instructions[0].destination.name == "dLoopbreak0"

0 comments on commit 17aa000

Please sign in to comment.