Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revive: Fix Hungarian Notation #416

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix: ArrayType,config,tests
  • Loading branch information
NeoQuix committed Jun 12, 2024
commit 17aa000c0a48823dda28d5541796a4636c61fc5b
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"
Loading