Skip to content

Commit

Permalink
Fix self variables not being recognized in 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
colinator27 committed Jun 29, 2024
1 parent 43a40b2 commit aa9822d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Underanalyzer/Decompiler/AST/Nodes/VariableCallNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Print(ASTPrinter printer)
{
// We have a "builtin" type on our variable, so use what's on the stack instead.
// Have to also check if we *need* "self." or not, if that's what Instance happens to be.
if (Instance is not InstanceTypeNode instType2 || instType2.InstanceType != IGMInstruction.InstanceType.Self ||
if (Instance is not InstanceTypeNode instType2 || instType2.InstanceType != IGMInstruction.InstanceType.Self || // TODO: for later investigation: does Builtin also need to be checked in 2024 versions?
printer.LocalVariableNames.Contains(variable.Variable.Name.Content) ||
printer.TopFragmentContext.NamedArguments.Contains(variable.Variable.Name.Content))
{
Expand Down
1 change: 1 addition & 0 deletions Underanalyzer/Decompiler/AST/Nodes/VariableNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public void Print(ASTPrinter printer)
switch (value)
{
case (int)InstanceType.Self:
case (int)InstanceType.Builtin:
if (printer.LocalVariableNames.Contains(Variable.Name.Content) ||
printer.TopFragmentContext.NamedArguments.Contains(Variable.Name.Content))
{
Expand Down
44 changes: 44 additions & 0 deletions UnderanalyzerTest/DecompileContext.DecompileToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,4 +1820,48 @@ function default_args_locals(arg0 = 123)
"""
);
}

[Fact]
public void TestArgumentsSelf()
{
TestUtil.VerifyDecompileResult(
"""
:[0]
b [4]
> gml_Script_default_arg_color (locals=0, args=1)
:[1]
push.v arg.argument0
pushbltn.v builtin.undefined
cmp.v.v EQ
bf [3]
:[2]
push.i 1
pop.v.i arg.argument0
:[3]
pushi.e 123
pop.v.i builtin.arg0
exit.i
:[4]
push.i [function]gml_Script_default_arg_color
conv.i.v
pushi.e -1
conv.i.v
call.i method 2
dup.v 0
pushi.e -1
pop.v.v [stacktop]self.default_arg_color
popz.v
""",
"""
function default_arg_color(arg0 = 1)
{
self.arg0 = 123;
}
"""
);
}
}

0 comments on commit aa9822d

Please sign in to comment.