Browse Source

fix output of generic methods and typeof

pull/728/head
Siegfried Pammer 10 years ago
parent
commit
51a26c416b
  1. 5
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 1
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj
  3. 51
      ICSharpCode.Decompiler/Tests/TestCases/Generics.cs
  4. 6
      ICSharpCode.Decompiler/Tests/TestRunner.cs
  5. 7
      ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

5
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -206,9 +206,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -206,9 +206,9 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitLdTypeToken(LdTypeToken inst)
{
return new TypeOfExpression(ConvertType(inst.Type))
return new TypeOfExpression(ConvertType(inst.Type)).Member("TypeHandle")
.WithILInstruction(inst)
.WithRR(new TypeOfResolveResult(compilation.FindType(KnownTypeCode.Type), inst.Type));
.WithRR(new TypeOfResolveResult(compilation.FindType(new TopLevelTypeName("System", "RuntimeTypeHandle")), inst.Type));
}
protected internal override TranslatedExpression VisitLogicNot(LogicNot inst)
@ -548,6 +548,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -548,6 +548,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
} else {
var mre = new MemberReferenceExpression(target.Expression, inst.Method.Name);
mre.TypeArguments.AddRange(inst.Method.TypeArguments.Select(a => ConvertType(a)));
expr = new InvocationExpression(mre, argumentExpressions);
}
return expr.WithILInstruction(inst).WithRR(rr);

1
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -105,6 +105,7 @@ @@ -105,6 +105,7 @@
<Compile Include="StackToVariablesTests.cs" />
<Compile Include="TestCases\CompoundAssignment.cs" />
<Compile Include="TestCases\ControlFlow.cs" />
<Compile Include="TestCases\Generics.cs" />
<Compile Include="TestCases\HelloWorld.cs" />
<Compile Include="TestCases\PropertiesAndEvents.cs" />
<Compile Include="TestCases\Switch.cs" />

51
ICSharpCode.Decompiler/Tests/TestCases/Generics.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
namespace Generics
{
/// <summary>
/// Description of Generics.
/// </summary>
public class Generics
{
public static void Main()
{
Console.WriteLine(TestGenericReturn<int>());
Console.WriteLine(TestGenericReturn<string>());
TestGenericParam<string>();
TestGenericParam<int, int>();
}
public static T TestGenericReturn<T>()
{
return default(T);
}
public static void TestGenericParam<T>()
{
Console.WriteLine(typeof(T));
}
public static void TestGenericParam<T1, T2>()
{
Console.WriteLine(typeof(T1) + " " + typeof(T2));
}
}
}

6
ICSharpCode.Decompiler/Tests/TestRunner.cs

@ -58,6 +58,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -58,6 +58,12 @@ namespace ICSharpCode.Decompiler.Tests
TestCompileDecompileCompileOutputAll("Switch.cs");
}
[Test]
public void Generics()
{
TestCompileDecompileCompileOutputAll("Generics.cs");
}
void TestCompileDecompileCompileOutputAll(string testFileName)
{
TestCompileDecompileCompileOutput(testFileName, CompilerOptions.None);

7
ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

@ -233,8 +233,11 @@ namespace ICSharpCode.Decompiler @@ -233,8 +233,11 @@ namespace ICSharpCode.Decompiler
var parameterTypes = methodReference.Parameters.SelectArray(p => Resolve(p.ParameterType));
var returnType = Resolve(methodReference.ReturnType);
foreach (var method in methods) {
if (CompareSignatures(method.Parameters, parameterTypes) && CompareTypes(method.ReturnType, returnType))
return method;
if (method.TypeParameters.Count != methodReference.GenericParameters.Count)
continue;
if (!CompareSignatures(method.Parameters, parameterTypes) || !CompareTypes(method.ReturnType, returnType))
continue;
return method;
}
return CreateFakeMethod(methodReference);
}

Loading…
Cancel
Save