Browse Source

Avoid redundant explicit boxing casts

pull/1129/head
Daniel Grunwald 7 years ago
parent
commit
d87820e226
  1. 10
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  2. 2
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs
  3. 21
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.il
  4. 21
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.opt.il
  5. 170
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.opt.roslyn.il
  6. 170
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.roslyn.il
  7. 5
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs
  8. 28
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il
  9. 22
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il
  10. 13
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il
  11. 19
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il
  12. 3
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  13. 10
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

10
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -110,7 +110,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -110,7 +110,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
if (asmOptions.HasFlag(AssemblerOptions.UseOwnDisassembler)) {
using (ModuleDefinition module = ModuleDefinition.ReadModule(sourceFileName))
using (var writer = new StreamWriter(outputFile)) {
using (var writer = new StringWriter()) {
module.Name = Path.GetFileNameWithoutExtension(outputFile);
var output = new PlainTextOutput(writer);
ReflectionDisassembler rd = new ReflectionDisassembler(output, CancellationToken.None);
@ -122,6 +122,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -122,6 +122,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
rd.WriteModuleHeader(module, skipMVID: true);
output.WriteLine();
rd.WriteModuleContents(module);
File.WriteAllText(outputFile, ReplacePrivImplDetails(writer.ToString()));
}
return outputFile;
}
@ -157,11 +159,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -157,11 +159,17 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
il = Regex.Replace(il, @"^// +Copyright .* Microsoft.*\r?\n", "", RegexOptions.Multiline);
// filename may contain full path
il = Regex.Replace(il, @"^// WARNING: Created Win32 resource file.*\r?\n", "", RegexOptions.Multiline);
il = ReplacePrivImplDetails(il);
File.WriteAllText(outputFile, il);
return outputFile;
}
private static string ReplacePrivImplDetails(string il)
{
return Regex.Replace(il, @"'<PrivateImplementationDetails>\{[0-9A-F-]+\}'", "'<PrivateImplementationDetails>'");
}
static readonly Lazy<IEnumerable<MetadataReference>> defaultReferences = new Lazy<IEnumerable<MetadataReference>>(delegate {
string refAsmPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
@"Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5");

2
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.cs

@ -218,7 +218,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -218,7 +218,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public void MembersBuiltin()
{
ToCode(X(), () => 1.23m.ToString());
ToCode(X(), () => ((Enum)(object)AttributeTargets.All).HasFlag((Enum)AttributeTargets.Assembly));
ToCode(X(), () => AttributeTargets.All.HasFlag((Enum)AttributeTargets.Assembly));
ToCode(X(), () => "abc".Length == 3);
ToCode(X(), () => 'a'.CompareTo('b') < 0);
}

21
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.il

@ -1,6 +1,4 @@ @@ -1,6 +1,4 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -20,7 +18,7 @@ @@ -20,7 +18,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly '3qhjq0hu'
.assembly ExpressionTrees
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
@ -30,15 +28,13 @@ @@ -30,15 +28,13 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module '3qhjq0hu.dll'
// MVID: {426C7905-90B3-4EA8-8585-F907E00CBDB7}
.module ExpressionTrees.dll
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02FC0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -9909,7 +9905,7 @@ @@ -9909,7 +9905,7 @@
IL_0000: ldc.i4.3
IL_0001: newarr [mscorlib]System.Int32
IL_0006: dup
IL_0007: ldtoken field valuetype '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'::'$$method0x60000bc-1'
IL_0007: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>'::'$$method0x60000bc-1'
IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0011: stloc.0
@ -9985,7 +9981,7 @@ @@ -9985,7 +9981,7 @@
IL_0009: ldc.i4.3
IL_000a: newarr [mscorlib]System.Int32
IL_000f: dup
IL_0010: ldtoken field valuetype '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'::'$$method0x60000c0-1'
IL_0010: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>'::'$$method0x60000c0-1'
IL_0015: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_001a: stelem.ref
@ -10676,7 +10672,7 @@ @@ -10676,7 +10672,7 @@
} // end of property '<>f__AnonymousType1`2'::Y
} // end of class '<>f__AnonymousType1`2'
.class private auto ansi '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'
.class private auto ansi '<PrivateImplementationDetails>'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
@ -10687,9 +10683,9 @@ @@ -10687,9 +10683,9 @@
.size 12
} // end of class '__StaticArrayInitTypeSize=12'
.field static assembly valuetype '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'/'__StaticArrayInitTypeSize=12' '$$method0x60000bc-1' at I_00007A38
.field static assembly valuetype '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'/'__StaticArrayInitTypeSize=12' '$$method0x60000c0-1' at I_00007AB0
} // end of class '<PrivateImplementationDetails>{426C7905-90B3-4EA8-8585-F907E00CBDB7}'
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '$$method0x60000bc-1' at I_00007A38
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '$$method0x60000c0-1' at I_00007AB0
} // end of class '<PrivateImplementationDetails>'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType2`2'<'<A>j__TPar','<B>j__TPar'>
extends [mscorlib]System.Object
@ -10886,4 +10882,3 @@ @@ -10886,4 +10882,3 @@
.data cil I_00007AB0 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00)
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../TestCases/Pretty\ExpressionTrees.res

21
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.opt.il

@ -1,6 +1,4 @@ @@ -1,6 +1,4 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -20,7 +18,7 @@ @@ -20,7 +18,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly tngduxjw
.assembly ExpressionTrees.opt
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
@ -30,15 +28,13 @@ @@ -30,15 +28,13 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module tngduxjw.dll
// MVID: {416BD71B-B506-4355-8604-9F8C6A2FDEE6}
.module ExpressionTrees.opt.dll
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x04A60000
// =============== CLASS MEMBERS DECLARATION ===================
@ -9453,7 +9449,7 @@ @@ -9453,7 +9449,7 @@
IL_0000: ldc.i4.3
IL_0001: newarr [mscorlib]System.Int32
IL_0006: dup
IL_0007: ldtoken field valuetype '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'::'$$method0x60000bc-1'
IL_0007: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>'::'$$method0x60000bc-1'
IL_000c: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_0011: ret
@ -9509,7 +9505,7 @@ @@ -9509,7 +9505,7 @@
IL_0009: ldc.i4.3
IL_000a: newarr [mscorlib]System.Int32
IL_000f: dup
IL_0010: ldtoken field valuetype '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'::'$$method0x60000c0-1'
IL_0010: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '<PrivateImplementationDetails>'::'$$method0x60000c0-1'
IL_0015: call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [mscorlib]System.Array,
valuetype [mscorlib]System.RuntimeFieldHandle)
IL_001a: stelem.ref
@ -10095,7 +10091,7 @@ @@ -10095,7 +10091,7 @@
} // end of property '<>f__AnonymousType1`2'::Y
} // end of class '<>f__AnonymousType1`2'
.class private auto ansi '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'
.class private auto ansi '<PrivateImplementationDetails>'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
@ -10106,9 +10102,9 @@ @@ -10106,9 +10102,9 @@
.size 12
} // end of class '__StaticArrayInitTypeSize=12'
.field static assembly valuetype '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'/'__StaticArrayInitTypeSize=12' '$$method0x60000bc-1' at I_00007670
.field static assembly valuetype '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'/'__StaticArrayInitTypeSize=12' '$$method0x60000c0-1' at I_000076A8
} // end of class '<PrivateImplementationDetails>{416BD71B-B506-4355-8604-9F8C6A2FDEE6}'
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '$$method0x60000bc-1' at I_00007670
.field static assembly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' '$$method0x60000c0-1' at I_000076A8
} // end of class '<PrivateImplementationDetails>'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType2`2'<'<A>j__TPar','<B>j__TPar'>
extends [mscorlib]System.Object
@ -10279,4 +10275,3 @@ @@ -10279,4 +10275,3 @@
.data cil I_000076A8 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00)
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../TestCases/Pretty\ExpressionTrees.opt.res

170
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.opt.roslyn.il

@ -3117,7 +3117,7 @@ @@ -3117,7 +3117,7 @@
.method public hidebysig instance void
MembersBuiltin() cil managed
{
// Code size 431 (0x1af)
// Code size 401 (0x191)
.maxstack 8
IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_0005: ldc.i4.s 123
@ -3157,108 +3157,100 @@ @@ -3157,108 +3157,100 @@
IL_0063: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0068: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_006d: ldtoken [mscorlib]System.Object
IL_0072: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0077: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Type)
IL_007c: ldtoken [mscorlib]System.Enum
IL_0081: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0086: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Type)
IL_008b: ldtoken method instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0090: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_0095: castclass [mscorlib]System.Reflection.MethodInfo
IL_009a: ldc.i4.1
IL_009b: newarr [System.Core]System.Linq.Expressions.Expression
IL_00a0: dup
IL_00a1: ldc.i4.0
IL_00a2: ldc.i4.1
IL_00a3: box [mscorlib]System.AttributeTargets
IL_00a8: ldtoken [mscorlib]System.AttributeTargets
IL_00ad: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00b2: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_00b7: ldtoken [mscorlib]System.Enum
IL_00bc: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00c1: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
IL_006d: ldtoken method instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0072: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_0077: castclass [mscorlib]System.Reflection.MethodInfo
IL_007c: ldc.i4.1
IL_007d: newarr [System.Core]System.Linq.Expressions.Expression
IL_0082: dup
IL_0083: ldc.i4.0
IL_0084: ldc.i4.1
IL_0085: box [mscorlib]System.AttributeTargets
IL_008a: ldtoken [mscorlib]System.AttributeTargets
IL_008f: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0094: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0099: ldtoken [mscorlib]System.Enum
IL_009e: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00a3: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Type)
IL_00c6: stelem.ref
IL_00c7: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
IL_00a8: stelem.ref
IL_00a9: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Reflection.MethodInfo,
class [System.Core]System.Linq.Expressions.Expression[])
IL_00cc: ldc.i4.0
IL_00cd: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_00d2: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
IL_00ae: ldc.i4.0
IL_00af: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_00b4: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.ParameterExpression[])
IL_00d7: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
IL_00b9: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
class [System.Core]System.Linq.Expressions.Expression`1<class [mscorlib]System.Func`1<!!0>>)
IL_00dc: pop
IL_00dd: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_00e2: ldstr "abc"
IL_00e7: ldtoken [mscorlib]System.String
IL_00ec: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00f1: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_00f6: ldtoken method instance int32 [mscorlib]System.String::get_Length()
IL_00fb: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_0100: castclass [mscorlib]System.Reflection.MethodInfo
IL_0105: call class [System.Core]System.Linq.Expressions.MemberExpression [System.Core]System.Linq.Expressions.Expression::Property(class [System.Core]System.Linq.Expressions.Expression,
IL_00be: pop
IL_00bf: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_00c4: ldstr "abc"
IL_00c9: ldtoken [mscorlib]System.String
IL_00ce: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00d3: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_00d8: ldtoken method instance int32 [mscorlib]System.String::get_Length()
IL_00dd: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_00e2: castclass [mscorlib]System.Reflection.MethodInfo
IL_00e7: call class [System.Core]System.Linq.Expressions.MemberExpression [System.Core]System.Linq.Expressions.Expression::Property(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Reflection.MethodInfo)
IL_010a: ldc.i4.3
IL_010b: box [mscorlib]System.Int32
IL_0110: ldtoken [mscorlib]System.Int32
IL_0115: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_011a: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
IL_00ec: ldc.i4.3
IL_00ed: box [mscorlib]System.Int32
IL_00f2: ldtoken [mscorlib]System.Int32
IL_00f7: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00fc: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_011f: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::Equal(class [System.Core]System.Linq.Expressions.Expression,
IL_0101: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::Equal(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.Expression)
IL_0124: ldc.i4.0
IL_0125: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_012a: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
IL_0106: ldc.i4.0
IL_0107: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_010c: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.ParameterExpression[])
IL_012f: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
IL_0111: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
class [System.Core]System.Linq.Expressions.Expression`1<class [mscorlib]System.Func`1<!!0>>)
IL_0134: pop
IL_0135: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_013a: ldc.i4.s 97
IL_013c: box [mscorlib]System.Char
IL_0141: ldtoken [mscorlib]System.Char
IL_0146: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_014b: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0150: ldtoken method instance int32 [mscorlib]System.Char::CompareTo(char)
IL_0155: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_015a: castclass [mscorlib]System.Reflection.MethodInfo
IL_015f: ldc.i4.1
IL_0160: newarr [System.Core]System.Linq.Expressions.Expression
IL_0165: dup
IL_0166: ldc.i4.0
IL_0167: ldc.i4.s 98
IL_0169: box [mscorlib]System.Char
IL_016e: ldtoken [mscorlib]System.Char
IL_0173: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0178: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_017d: stelem.ref
IL_017e: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
IL_0116: pop
IL_0117: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_011c: ldc.i4.s 97
IL_011e: box [mscorlib]System.Char
IL_0123: ldtoken [mscorlib]System.Char
IL_0128: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_012d: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0132: ldtoken method instance int32 [mscorlib]System.Char::CompareTo(char)
IL_0137: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_013c: castclass [mscorlib]System.Reflection.MethodInfo
IL_0141: ldc.i4.1
IL_0142: newarr [System.Core]System.Linq.Expressions.Expression
IL_0147: dup
IL_0148: ldc.i4.0
IL_0149: ldc.i4.s 98
IL_014b: box [mscorlib]System.Char
IL_0150: ldtoken [mscorlib]System.Char
IL_0155: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_015a: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_015f: stelem.ref
IL_0160: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Reflection.MethodInfo,
class [System.Core]System.Linq.Expressions.Expression[])
IL_0183: ldc.i4.0
IL_0184: box [mscorlib]System.Int32
IL_0189: ldtoken [mscorlib]System.Int32
IL_018e: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0193: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
IL_0165: ldc.i4.0
IL_0166: box [mscorlib]System.Int32
IL_016b: ldtoken [mscorlib]System.Int32
IL_0170: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0175: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0198: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::LessThan(class [System.Core]System.Linq.Expressions.Expression,
IL_017a: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::LessThan(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.Expression)
IL_019d: ldc.i4.0
IL_019e: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_01a3: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
IL_017f: ldc.i4.0
IL_0180: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_0185: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.ParameterExpression[])
IL_01a8: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
IL_018a: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
class [System.Core]System.Linq.Expressions.Expression`1<class [mscorlib]System.Func`1<!!0>>)
IL_01ad: pop
IL_01ae: ret
IL_018f: pop
IL_0190: ret
} // end of method ExpressionTrees::MembersBuiltin
.method public hidebysig instance void
@ -9680,12 +9672,12 @@ @@ -9680,12 +9672,12 @@
.size 12
} // end of class '__StaticArrayInitTypeSize=12'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_0000BDA0
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_0000BD84
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_0000BDA0 = bytearray (
.data cil I_0000BD84 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00)
// *********** DISASSEMBLY COMPLETE ***********************

170
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpressionTrees.roslyn.il

@ -3201,7 +3201,7 @@ @@ -3201,7 +3201,7 @@
.method public hidebysig instance void
MembersBuiltin() cil managed
{
// Code size 432 (0x1b0)
// Code size 402 (0x192)
.maxstack 8
IL_0000: nop
IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
@ -3242,108 +3242,100 @@ @@ -3242,108 +3242,100 @@
IL_0064: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0069: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_006e: ldtoken [mscorlib]System.Object
IL_0073: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0078: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Type)
IL_007d: ldtoken [mscorlib]System.Enum
IL_0082: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0087: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Type)
IL_008c: ldtoken method instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0091: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_0096: castclass [mscorlib]System.Reflection.MethodInfo
IL_009b: ldc.i4.1
IL_009c: newarr [System.Core]System.Linq.Expressions.Expression
IL_00a1: dup
IL_00a2: ldc.i4.0
IL_00a3: ldc.i4.1
IL_00a4: box [mscorlib]System.AttributeTargets
IL_00a9: ldtoken [mscorlib]System.AttributeTargets
IL_00ae: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00b3: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_00b8: ldtoken [mscorlib]System.Enum
IL_00bd: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00c2: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
IL_006e: ldtoken method instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0073: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_0078: castclass [mscorlib]System.Reflection.MethodInfo
IL_007d: ldc.i4.1
IL_007e: newarr [System.Core]System.Linq.Expressions.Expression
IL_0083: dup
IL_0084: ldc.i4.0
IL_0085: ldc.i4.1
IL_0086: box [mscorlib]System.AttributeTargets
IL_008b: ldtoken [mscorlib]System.AttributeTargets
IL_0090: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0095: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_009a: ldtoken [mscorlib]System.Enum
IL_009f: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00a4: call class [System.Core]System.Linq.Expressions.UnaryExpression [System.Core]System.Linq.Expressions.Expression::Convert(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Type)
IL_00c7: stelem.ref
IL_00c8: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
IL_00a9: stelem.ref
IL_00aa: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Reflection.MethodInfo,
class [System.Core]System.Linq.Expressions.Expression[])
IL_00cd: ldc.i4.0
IL_00ce: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_00d3: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
IL_00af: ldc.i4.0
IL_00b0: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_00b5: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.ParameterExpression[])
IL_00d8: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
IL_00ba: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
class [System.Core]System.Linq.Expressions.Expression`1<class [mscorlib]System.Func`1<!!0>>)
IL_00dd: pop
IL_00de: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_00e3: ldstr "abc"
IL_00e8: ldtoken [mscorlib]System.String
IL_00ed: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00f2: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_00f7: ldtoken method instance int32 [mscorlib]System.String::get_Length()
IL_00fc: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_0101: castclass [mscorlib]System.Reflection.MethodInfo
IL_0106: call class [System.Core]System.Linq.Expressions.MemberExpression [System.Core]System.Linq.Expressions.Expression::Property(class [System.Core]System.Linq.Expressions.Expression,
IL_00bf: pop
IL_00c0: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_00c5: ldstr "abc"
IL_00ca: ldtoken [mscorlib]System.String
IL_00cf: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00d4: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_00d9: ldtoken method instance int32 [mscorlib]System.String::get_Length()
IL_00de: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_00e3: castclass [mscorlib]System.Reflection.MethodInfo
IL_00e8: call class [System.Core]System.Linq.Expressions.MemberExpression [System.Core]System.Linq.Expressions.Expression::Property(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Reflection.MethodInfo)
IL_010b: ldc.i4.3
IL_010c: box [mscorlib]System.Int32
IL_0111: ldtoken [mscorlib]System.Int32
IL_0116: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_011b: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
IL_00ed: ldc.i4.3
IL_00ee: box [mscorlib]System.Int32
IL_00f3: ldtoken [mscorlib]System.Int32
IL_00f8: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_00fd: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0120: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::Equal(class [System.Core]System.Linq.Expressions.Expression,
IL_0102: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::Equal(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.Expression)
IL_0125: ldc.i4.0
IL_0126: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_012b: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
IL_0107: ldc.i4.0
IL_0108: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_010d: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.ParameterExpression[])
IL_0130: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
IL_0112: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
class [System.Core]System.Linq.Expressions.Expression`1<class [mscorlib]System.Func`1<!!0>>)
IL_0135: pop
IL_0136: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_013b: ldc.i4.s 97
IL_013d: box [mscorlib]System.Char
IL_0142: ldtoken [mscorlib]System.Char
IL_0147: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_014c: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0151: ldtoken method instance int32 [mscorlib]System.Char::CompareTo(char)
IL_0156: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_015b: castclass [mscorlib]System.Reflection.MethodInfo
IL_0160: ldc.i4.1
IL_0161: newarr [System.Core]System.Linq.Expressions.Expression
IL_0166: dup
IL_0167: ldc.i4.0
IL_0168: ldc.i4.s 98
IL_016a: box [mscorlib]System.Char
IL_016f: ldtoken [mscorlib]System.Char
IL_0174: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0179: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_017e: stelem.ref
IL_017f: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
IL_0117: pop
IL_0118: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::X()
IL_011d: ldc.i4.s 97
IL_011f: box [mscorlib]System.Char
IL_0124: ldtoken [mscorlib]System.Char
IL_0129: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_012e: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0133: ldtoken method instance int32 [mscorlib]System.Char::CompareTo(char)
IL_0138: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
IL_013d: castclass [mscorlib]System.Reflection.MethodInfo
IL_0142: ldc.i4.1
IL_0143: newarr [System.Core]System.Linq.Expressions.Expression
IL_0148: dup
IL_0149: ldc.i4.0
IL_014a: ldc.i4.s 98
IL_014c: box [mscorlib]System.Char
IL_0151: ldtoken [mscorlib]System.Char
IL_0156: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_015b: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0160: stelem.ref
IL_0161: call class [System.Core]System.Linq.Expressions.MethodCallExpression [System.Core]System.Linq.Expressions.Expression::Call(class [System.Core]System.Linq.Expressions.Expression,
class [mscorlib]System.Reflection.MethodInfo,
class [System.Core]System.Linq.Expressions.Expression[])
IL_0184: ldc.i4.0
IL_0185: box [mscorlib]System.Int32
IL_018a: ldtoken [mscorlib]System.Int32
IL_018f: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0194: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
IL_0166: ldc.i4.0
IL_0167: box [mscorlib]System.Int32
IL_016c: ldtoken [mscorlib]System.Int32
IL_0171: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_0176: call class [System.Core]System.Linq.Expressions.ConstantExpression [System.Core]System.Linq.Expressions.Expression::Constant(object,
class [mscorlib]System.Type)
IL_0199: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::LessThan(class [System.Core]System.Linq.Expressions.Expression,
IL_017b: call class [System.Core]System.Linq.Expressions.BinaryExpression [System.Core]System.Linq.Expressions.Expression::LessThan(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.Expression)
IL_019e: ldc.i4.0
IL_019f: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_01a4: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
IL_0180: ldc.i4.0
IL_0181: newarr [System.Core]System.Linq.Expressions.ParameterExpression
IL_0186: call class [System.Core]System.Linq.Expressions.Expression`1<!!0> [System.Core]System.Linq.Expressions.Expression::Lambda<class [mscorlib]System.Func`1<bool>>(class [System.Core]System.Linq.Expressions.Expression,
class [System.Core]System.Linq.Expressions.ParameterExpression[])
IL_01a9: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
IL_018b: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.ExpressionTrees::ToCode<bool>(object,
class [System.Core]System.Linq.Expressions.Expression`1<class [mscorlib]System.Func`1<!!0>>)
IL_01ae: pop
IL_01af: ret
IL_0190: pop
IL_0191: ret
} // end of method ExpressionTrees::MembersBuiltin
.method public hidebysig instance void
@ -9927,12 +9919,12 @@ @@ -9927,12 +9919,12 @@
.size 12
} // end of class '__StaticArrayInitTypeSize=12'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_0000C030
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=12' E429CCA3F703A39CC5954A6572FEC9086135B34E at I_0000C014
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_0000C030 = bytearray (
.data cil I_0000C014 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00)
// *********** DISASSEMBLY COMPLETE ***********************

5
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.cs

@ -244,5 +244,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -244,5 +244,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
return string.Equals("", "", b ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);
}
public bool MethodCallOnEnumConstant()
{
return AttributeTargets.All.HasFlag(AttributeTargets.Assembly);
}
}
}

28
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.il

@ -1,6 +1,4 @@ @@ -1,6 +1,4 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +8,7 @@ @@ -10,7 +8,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly mu5mxl5m
.assembly TypeAnalysisTests
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
@ -20,15 +18,13 @@ @@ -20,15 +18,13 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module mu5mxl5m.dll
// MVID: {DBFE6CB1-ED58-473D-986E-A633C15C8AEE}
.module TypeAnalysisTests.dll
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x04E10000
// =============== CLASS MEMBERS DECLARATION ===================
@ -848,6 +844,25 @@ @@ -848,6 +844,25 @@
IL_001c: ret
} // end of method TypeAnalysisTests::EnumInConditionalOperator
.method public hidebysig instance bool
MethodCallOnEnumConstant() cil managed
{
// Code size 27 (0x1b)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldc.i4 0x7fff
IL_0006: box [mscorlib]System.AttributeTargets
IL_000b: ldc.i4.1
IL_000c: box [mscorlib]System.AttributeTargets
IL_0011: call instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0016: stloc.0
IL_0017: br.s IL_0019
IL_0019: ldloc.0
IL_001a: ret
} // end of method TypeAnalysisTests::MethodCallOnEnumConstant
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -864,4 +879,3 @@ @@ -864,4 +879,3 @@
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../TestCases/Pretty\TypeAnalysisTests.res

22
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.il

@ -1,6 +1,4 @@ @@ -1,6 +1,4 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +8,7 @@ @@ -10,7 +8,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly tbojr2zd
.assembly TypeAnalysisTests.opt
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
@ -20,15 +18,13 @@ @@ -20,15 +18,13 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module tbojr2zd.dll
// MVID: {A417EC21-8726-4629-9E82-47FE9895CD81}
.module TypeAnalysisTests.opt.dll
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x05150000
// =============== CLASS MEMBERS DECLARATION ===================
@ -586,6 +582,19 @@ @@ -586,6 +582,19 @@
IL_0016: ret
} // end of method TypeAnalysisTests::EnumInConditionalOperator
.method public hidebysig instance bool
MethodCallOnEnumConstant() cil managed
{
// Code size 22 (0x16)
.maxstack 8
IL_0000: ldc.i4 0x7fff
IL_0005: box [mscorlib]System.AttributeTargets
IL_000a: ldc.i4.1
IL_000b: box [mscorlib]System.AttributeTargets
IL_0010: call instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0015: ret
} // end of method TypeAnalysisTests::MethodCallOnEnumConstant
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -602,4 +611,3 @@ @@ -602,4 +611,3 @@
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../TestCases/Pretty\TypeAnalysisTests.opt.res

13
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.opt.roslyn.il

@ -584,6 +584,19 @@ @@ -584,6 +584,19 @@
IL_0016: ret
} // end of method TypeAnalysisTests::EnumInConditionalOperator
.method public hidebysig instance bool
MethodCallOnEnumConstant() cil managed
{
// Code size 22 (0x16)
.maxstack 8
IL_0000: ldc.i4 0x7fff
IL_0005: box [mscorlib]System.AttributeTargets
IL_000a: ldc.i4.1
IL_000b: box [mscorlib]System.AttributeTargets
IL_0010: call instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0015: ret
} // end of method TypeAnalysisTests::MethodCallOnEnumConstant
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

19
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TypeAnalysisTests.roslyn.il

@ -842,6 +842,25 @@ @@ -842,6 +842,25 @@
IL_001b: ret
} // end of method TypeAnalysisTests::EnumInConditionalOperator
.method public hidebysig instance bool
MethodCallOnEnumConstant() cil managed
{
// Code size 27 (0x1b)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldc.i4 0x7fff
IL_0006: box [mscorlib]System.AttributeTargets
IL_000b: ldc.i4.1
IL_000c: box [mscorlib]System.AttributeTargets
IL_0011: call instance bool [mscorlib]System.Enum::HasFlag(class [mscorlib]System.Enum)
IL_0016: stloc.0
IL_0017: br.s IL_0019
IL_0019: ldloc.0
IL_001a: ret
} // end of method TypeAnalysisTests::MethodCallOnEnumConstant
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

3
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -71,8 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -71,8 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp
target = default(TranslatedExpression); // no target
} else {
target = expressionBuilder.TranslateTarget(method, callArguments.FirstOrDefault(), callOpCode == OpCode.Call, constrainedTo);
if (callOpCode == OpCode.CallVirt
&& constrainedTo == null
if (constrainedTo == null
&& target.Expression is CastExpression cast
&& target.ResolveResult is ConversionResolveResult conversion
&& target.Type.IsKnownType(KnownTypeCode.Object)

10
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -201,6 +201,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -201,6 +201,14 @@ namespace ICSharpCode.Decompiler.CSharp
if (targetType.Kind == TypeKind.Unknown || targetType.Kind == TypeKind.Void) {
return this; // don't attempt to insert cast to '?' or 'void' as these are not valid.
}
var compilation = expressionBuilder.compilation;
var conversions = Resolver.CSharpConversions.Get(compilation);
if (ResolveResult is ConversionResolveResult conv && Expression is CastExpression cast2 && conv.Conversion.IsBoxingConversion && conversions.IsBoxingConversion(conv.Input.Type, targetType)) {
var unwrapped = this.UnwrapChild(cast2.Expression);
if (allowImplicitConversion)
return unwrapped;
return unwrapped.ConvertTo(targetType, expressionBuilder, checkForOverflow, allowImplicitConversion);
}
if (Expression is UnaryOperatorExpression uoe && uoe.Operator == UnaryOperatorType.NullConditional && targetType.IsReferenceType == true) {
// "(T)(x?).AccessChain" is invalid, but "((T)x)?.AccessChain" is valid and equivalent
return new UnaryOperatorExpression(
@ -208,7 +216,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -208,7 +216,6 @@ namespace ICSharpCode.Decompiler.CSharp
UnwrapChild(uoe.Expression).ConvertTo(targetType, expressionBuilder, checkForOverflow, allowImplicitConversion)
).WithRR(new ResolveResult(targetType)).WithoutILInstruction();
}
var compilation = expressionBuilder.compilation;
bool isLifted = type.IsKnownType(KnownTypeCode.NullableOfT) && targetType.IsKnownType(KnownTypeCode.NullableOfT);
IType utype = isLifted ? NullableType.GetUnderlyingType(type) : type;
IType targetUType = isLifted ? NullableType.GetUnderlyingType(targetType) : targetType;
@ -350,7 +357,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -350,7 +357,6 @@ namespace ICSharpCode.Decompiler.CSharp
.WithILInstruction(this.ILInstructions)
.WithRR(new ConstantResolveResult(targetType, null));
}
var conversions = Resolver.CSharpConversions.Get(compilation);
if (allowImplicitConversion && conversions.ImplicitConversion(type, targetType).IsValid) {
return this;
}

Loading…
Cancel
Save