Browse Source

Support array slicing.

pull/1986/head
Daniel Grunwald 5 years ago
parent
commit
748c54a1c1
  1. 16
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/IndexRangeTest.cs
  2. 7
      ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs

16
ICSharpCode.Decompiler.Tests/TestCases/Pretty/IndexRangeTest.cs

@ -103,8 +103,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void UseRange() public static void UseRange()
{ {
#if TODO
Console.WriteLine(GetArray()[GetRange()]); Console.WriteLine(GetArray()[GetRange()]);
#if TODO
//Console.WriteLine(GetList()[GetRange()]); // fails to compile //Console.WriteLine(GetList()[GetRange()]); // fails to compile
Console.WriteLine(GetSpan()[GetRange()].ToString()); Console.WriteLine(GetSpan()[GetRange()].ToString());
Console.WriteLine(GetString()[GetRange()]); Console.WriteLine(GetString()[GetRange()]);
@ -114,8 +114,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
public static void UseNewRangeFromIndex() public static void UseNewRangeFromIndex()
{ {
#if TODO
Console.WriteLine(GetArray()[GetIndex()..GetIndex()]); Console.WriteLine(GetArray()[GetIndex()..GetIndex()]);
#if TODO
//Console.WriteLine(GetList()[GetIndex()..GetIndex()]); // fails to compile //Console.WriteLine(GetList()[GetIndex()..GetIndex()]); // fails to compile
Console.WriteLine(GetSpan()[GetIndex()..GetIndex()].ToString()); Console.WriteLine(GetSpan()[GetIndex()..GetIndex()].ToString());
Console.WriteLine(GetString()[GetIndex()..GetIndex()]); Console.WriteLine(GetString()[GetIndex()..GetIndex()]);
@ -125,8 +125,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
public static void UseNewRangeFromIntegers_BothFromStart() public static void UseNewRangeFromIntegers_BothFromStart()
{ {
#if TODO
Console.WriteLine(GetArray()[GetInt(1)..GetInt(2)]); Console.WriteLine(GetArray()[GetInt(1)..GetInt(2)]);
#if TODO
//Console.WriteLine(GetList()[GetInt()..GetInt()]); // fails to compile //Console.WriteLine(GetList()[GetInt()..GetInt()]); // fails to compile
Console.WriteLine(GetSpan()[GetInt(1)..GetInt(2)].ToString()); Console.WriteLine(GetSpan()[GetInt(1)..GetInt(2)].ToString());
Console.WriteLine(GetString()[GetInt(1)..GetInt(2)]); Console.WriteLine(GetString()[GetInt(1)..GetInt(2)]);
@ -136,8 +136,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
public static void UseNewRangeFromIntegers_BothFromEnd() public static void UseNewRangeFromIntegers_BothFromEnd()
{ {
#if TODO
Console.WriteLine(GetArray()[^GetInt(1)..^GetInt(2)]); Console.WriteLine(GetArray()[^GetInt(1)..^GetInt(2)]);
#if TODO
//Console.WriteLine(GetList()[^GetInt()..^GetInt()]); // fails to compile //Console.WriteLine(GetList()[^GetInt()..^GetInt()]); // fails to compile
Console.WriteLine(GetSpan()[^GetInt(1)..^GetInt(2)].ToString()); Console.WriteLine(GetSpan()[^GetInt(1)..^GetInt(2)].ToString());
Console.WriteLine(GetString()[^GetInt(1)..^GetInt(2)]); Console.WriteLine(GetString()[^GetInt(1)..^GetInt(2)]);
@ -158,8 +158,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
public static void UseNewRangeFromIntegers_FromEndAndStart() public static void UseNewRangeFromIntegers_FromEndAndStart()
{ {
#if TODO
Console.WriteLine(GetArray()[^GetInt(1)..GetInt(2)]); Console.WriteLine(GetArray()[^GetInt(1)..GetInt(2)]);
#if TODO
//Console.WriteLine(GetList()[^GetInt()..GetInt()]); // fails to compile //Console.WriteLine(GetList()[^GetInt()..GetInt()]); // fails to compile
Console.WriteLine(GetSpan()[^GetInt(1)..GetInt(2)].ToString()); Console.WriteLine(GetSpan()[^GetInt(1)..GetInt(2)].ToString());
Console.WriteLine(GetString()[^GetInt(1)..GetInt(2)]); Console.WriteLine(GetString()[^GetInt(1)..GetInt(2)]);
@ -170,8 +170,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void UseNewRangeFromIntegers_OnlyEndPoint() public static void UseNewRangeFromIntegers_OnlyEndPoint()
{ {
#if TODO
Console.WriteLine(GetArray()[..GetInt(2)]); Console.WriteLine(GetArray()[..GetInt(2)]);
#if TODO
//Console.WriteLine(GetList()[..GetInt()]); // fails to compile //Console.WriteLine(GetList()[..GetInt()]); // fails to compile
Console.WriteLine(GetSpan()[..GetInt(2)].ToString()); Console.WriteLine(GetSpan()[..GetInt(2)].ToString());
Console.WriteLine(GetString()[..GetInt(2)]); Console.WriteLine(GetString()[..GetInt(2)]);
@ -182,8 +182,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void UseNewRangeFromIntegers_OnlyStartPoint() public static void UseNewRangeFromIntegers_OnlyStartPoint()
{ {
#if TODO
Console.WriteLine(GetArray()[GetInt(1)..]); Console.WriteLine(GetArray()[GetInt(1)..]);
#if TODO
//Console.WriteLine(GetList()[GetInt()..]); // fails to compile //Console.WriteLine(GetList()[GetInt()..]); // fails to compile
Console.WriteLine(GetSpan()[GetInt(1)..].ToString()); Console.WriteLine(GetSpan()[GetInt(1)..].ToString());
Console.WriteLine(GetString()[GetInt(1)..]); Console.WriteLine(GetString()[GetInt(1)..]);
@ -194,8 +194,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public static void UseWholeRange() public static void UseWholeRange()
{ {
#if TODO
Console.WriteLine(GetArray()[..]); Console.WriteLine(GetArray()[..]);
#if TODO
//Console.WriteLine(GetList()[..]); // fails to compile //Console.WriteLine(GetList()[..]); // fails to compile
Console.WriteLine(GetSpan()[..].ToString()); Console.WriteLine(GetSpan()[..].ToString());
Console.WriteLine(GetString()[..]); Console.WriteLine(GetString()[..]);

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

@ -125,6 +125,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
invocationExpression.ReplaceWith(new ObjectCreateExpression(context.TypeSystemAstBuilder.ConvertType(method.TypeArguments.First()))); invocationExpression.ReplaceWith(new ObjectCreateExpression(context.TypeSystemAstBuilder.ConvertType(method.TypeArguments.First())));
} }
break; break;
case "System.Runtime.CompilerServices.RuntimeHelpers.GetSubArray":
if (arguments.Length == 2 && context.Settings.Ranges) {
var slicing = new IndexerExpression(arguments[0].Detach(), arguments[1].Detach());
slicing.CopyAnnotationsFrom(invocationExpression);
invocationExpression.ReplaceWith(slicing);
}
break;
} }
BinaryOperatorType? bop = GetBinaryOperatorTypeFromMetadataName(method.Name); BinaryOperatorType? bop = GetBinaryOperatorTypeFromMetadataName(method.Name);

Loading…
Cancel
Save