Browse Source

Add more tests, fix typo.

pull/1243/head
Siegfried Pammer 8 years ago
parent
commit
9ed65dc780
  1. 5
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs
  2. 64
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.opt.roslyn.il
  3. 67
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.roslyn.il
  4. 25
      ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs
  5. 2
      ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemTestCase.cs
  6. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultParameter.cs
  7. 12
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs

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

@ -11,5 +11,10 @@ @@ -11,5 +11,10 @@
{
private readonly int dummy;
}
public readonly struct ReadOnlyStruct
{
private readonly int dummy;
}
}
}

64
ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.opt.roslyn.il

@ -33,64 +33,13 @@ @@ -33,64 +33,13 @@
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi sealed beforefieldinit Microsoft.CodeAnalysis.EmbeddedAttribute
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method EmbeddedAttribute::.ctor
} // end of class Microsoft.CodeAnalysis.EmbeddedAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsReadOnlyAttribute
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method IsReadOnlyAttribute::.ctor
} // end of class System.Runtime.CompilerServices.IsReadOnlyAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsByRefLikeAttribute
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method IsByRefLikeAttribute::.ctor
} // end of class System.Runtime.CompilerServices.IsByRefLikeAttribute
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.RefLocalsAndReturns
extends [mscorlib]System.Object
{
.class sequential ansi sealed nested public beforefieldinit RefStruct
extends [mscorlib]System.ValueType
{
.custom instance void System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor(string,
bool) = ( 01 00 52 54 79 70 65 73 20 77 69 74 68 20 65 6D // ..RTypes with em
62 65 64 64 65 64 20 72 65 66 65 72 65 6E 63 65 // bedded reference
@ -104,7 +53,7 @@ @@ -104,7 +53,7 @@
.class sequential ansi sealed nested public beforefieldinit ReadOnlyRefStruct
extends [mscorlib]System.ValueType
{
.custom instance void System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor(string,
bool) = ( 01 00 52 54 79 70 65 73 20 77 69 74 68 20 65 6D // ..RTypes with em
62 65 64 64 65 64 20 72 65 66 65 72 65 6E 63 65 // bedded reference
@ -112,10 +61,17 @@ @@ -112,10 +61,17 @@
74 65 64 20 69 6E 20 74 68 69 73 20 76 65 72 73 // ted in this vers
69 6F 6E 20 6F 66 20 79 6F 75 72 20 63 6F 6D 70 // ion of your comp
69 6C 65 72 2E 01 00 00 ) // iler....
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly int32 dummy
} // end of class ReadOnlyRefStruct
.class sequential ansi sealed nested public beforefieldinit ReadOnlyStruct
extends [mscorlib]System.ValueType
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly int32 dummy
} // end of class ReadOnlyStruct
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

67
ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.roslyn.il

@ -33,67 +33,13 @@ @@ -33,67 +33,13 @@
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi sealed beforefieldinit Microsoft.CodeAnalysis.EmbeddedAttribute
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method EmbeddedAttribute::.ctor
} // end of class Microsoft.CodeAnalysis.EmbeddedAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsReadOnlyAttribute
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method IsReadOnlyAttribute::.ctor
} // end of class System.Runtime.CompilerServices.IsReadOnlyAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsByRefLikeAttribute
extends [mscorlib]System.Attribute
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method IsByRefLikeAttribute::.ctor
} // end of class System.Runtime.CompilerServices.IsByRefLikeAttribute
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.RefLocalsAndReturns
extends [mscorlib]System.Object
{
.class sequential ansi sealed nested public beforefieldinit RefStruct
extends [mscorlib]System.ValueType
{
.custom instance void System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor(string,
bool) = ( 01 00 52 54 79 70 65 73 20 77 69 74 68 20 65 6D // ..RTypes with em
62 65 64 64 65 64 20 72 65 66 65 72 65 6E 63 65 // bedded reference
@ -107,7 +53,7 @@ @@ -107,7 +53,7 @@
.class sequential ansi sealed nested public beforefieldinit ReadOnlyRefStruct
extends [mscorlib]System.ValueType
{
.custom instance void System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor(string,
bool) = ( 01 00 52 54 79 70 65 73 20 77 69 74 68 20 65 6D // ..RTypes with em
62 65 64 64 65 64 20 72 65 66 65 72 65 6E 63 65 // bedded reference
@ -115,10 +61,17 @@ @@ -115,10 +61,17 @@
74 65 64 20 69 6E 20 74 68 69 73 20 76 65 72 73 // ted in this vers
69 6F 6E 20 6F 66 20 79 6F 75 72 20 63 6F 6D 70 // ion of your comp
69 6C 65 72 2E 01 00 00 ) // iler....
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly int32 dummy
} // end of class ReadOnlyRefStruct
.class sequential ansi sealed nested public beforefieldinit ReadOnlyStruct
extends [mscorlib]System.ValueType
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly int32 dummy
} // end of class ReadOnlyStruct
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

25
ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs

@ -634,6 +634,31 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem @@ -634,6 +634,31 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem
Assert.IsFalse(p.IsOptional);
Assert.IsFalse(p.IsRef);
Assert.IsTrue(p.IsOut);
Assert.IsFalse(p.IsIn);
Assert.AreEqual(0, p.GetAttributes().Count());
Assert.IsTrue(p.Type.Kind == TypeKind.ByReference);
}
[Test]
public void MethodWithRefParameter()
{
IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithRefParameter").Parameters.Single();
Assert.IsFalse(p.IsOptional);
Assert.IsTrue(p.IsRef);
Assert.IsFalse(p.IsOut);
Assert.IsFalse(p.IsIn);
Assert.AreEqual(0, p.GetAttributes().Count());
Assert.IsTrue(p.Type.Kind == TypeKind.ByReference);
}
[Test]
public void MethodWithInParameter()
{
IParameter p = GetTypeDefinition(typeof(ParameterTests)).Methods.Single(m => m.Name == "MethodWithInParameter").Parameters.Single();
Assert.IsFalse(p.IsOptional);
Assert.IsFalse(p.IsRef);
Assert.IsFalse(p.IsOut);
Assert.IsTrue(p.IsIn);
Assert.AreEqual(0, p.GetAttributes().Count());
Assert.IsTrue(p.Type.Kind == TypeKind.ByReference);
}

2
ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemTestCase.cs

@ -158,6 +158,8 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem @@ -158,6 +158,8 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem
public void MethodWithParamsArray(params object[] x) { }
public void MethodWithOptionalParameter(int x = 4) { }
public void MethodWithExplicitOptionalParameter([Optional] int x) { }
public void MethodWithRefParameter(ref int x) { }
public void MethodWithInParameter(in int x) { }
public void MethodWithEnumOptionalParameter(StringComparison x = StringComparison.OrdinalIgnoreCase) { }
public void MethodWithOptionalNullableParameter(int? x = null) { }
public void MethodWithOptionalLongParameter(long x = 1) { }

2
ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultParameter.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
}
public bool IsIn {
get { return IsIn; }
get { return isIn; }
}
public bool IsParams {

12
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs

@ -80,7 +80,17 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -80,7 +80,17 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#endregion
const ParameterAttributes inOut = ParameterAttributes.In | ParameterAttributes.Out;
public bool IsRef => Type.Kind == TypeKind.ByReference && (attributes & inOut) == 0;
public bool IsRef {
get {
if (!(Type.Kind == TypeKind.ByReference && (attributes & inOut) != ParameterAttributes.Out))
return false;
var metadata = module.metadata;
var parameterDef = metadata.GetParameter(handle);
return !parameterDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.IsReadOnly);
}
}
public bool IsOut => Type.Kind == TypeKind.ByReference && (attributes & inOut) == ParameterAttributes.Out;
public bool IsOptional => (attributes & ParameterAttributes.Optional) != 0;

Loading…
Cancel
Save