Browse Source

implement support for op_True and extend unit test

pull/143/merge
Siegfried Pammer 15 years ago
parent
commit
f86fa5d1dd
  1. 7
      ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs
  2. 32
      ICSharpCode.Decompiler/Tests/CustomShortCircuitOperators.cs

7
ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs

@ -50,7 +50,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -50,7 +50,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
var arguments = invocationExpression.Arguments.ToArray();
// Reduce "String.Concat(a, b)" to "a + b"
if (methodRef != null && methodRef.Name == "Concat" && methodRef.DeclaringType.FullName == "System.String" && arguments.Length >= 2)
if (methodRef.Name == "Concat" && methodRef.DeclaringType.FullName == "System.String" && arguments.Length >= 2)
{
invocationExpression.Arguments.Clear(); // detach arguments from invocationExpression
Expression expr = arguments[0];
@ -97,7 +97,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -97,7 +97,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
return null;
}
if (methodRef.Name == "op_Implicit" && arguments.Length == 1) {
arguments[0].Remove(); // detach argument
invocationExpression.ReplaceWith(arguments[0]);
return null;
}
if (methodRef.Name == "op_True" && arguments.Length == 1 && invocationExpression.Role == AstNode.Roles.Condition) {
invocationExpression.ReplaceWith(arguments[0]);
return null;
}

32
ICSharpCode.Decompiler/Tests/CustomShortCircuitOperators.cs

@ -29,6 +29,11 @@ public static class CustomShortCircuitOperators @@ -29,6 +29,11 @@ public static class CustomShortCircuitOperators
{
return null;
}
public static bool operator !(CustomShortCircuitOperators.C x)
{
return false;
}
private static void Main()
{
@ -39,5 +44,32 @@ public static class CustomShortCircuitOperators @@ -39,5 +44,32 @@ public static class CustomShortCircuitOperators
Console.WriteLine(c3.ToString());
Console.WriteLine(c4.ToString());
}
private static void Test2()
{
CustomShortCircuitOperators.C c = new CustomShortCircuitOperators.C();
if (c && c)
{
Console.WriteLine(c.ToString());
}
if (!(c && c))
{
Console.WriteLine(c.ToString());
}
}
private static void Test3()
{
CustomShortCircuitOperators.C c = new CustomShortCircuitOperators.C();
if (c)
{
Console.WriteLine(c.ToString());
}
if (!c)
{
Console.WriteLine(c.ToString());
}
}
}
}
Loading…
Cancel
Save