Browse Source

TypeSystem helper for unit tests

pull/728/head
Daniel Grunwald 11 years ago
parent
commit
7c318157d5
  1. 18
      ICSharpCode.Decompiler/IL/Instructions/Block.cs
  2. 2
      ICSharpCode.Decompiler/IL/SemanticHelper.cs
  3. 3
      ICSharpCode.Decompiler/Properties/AssemblyInfo.template.cs
  4. 51
      ICSharpCode.Decompiler/Tests/Helpers/TypeSystemHelper.cs
  5. 15
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj
  6. 52
      ICSharpCode.Decompiler/Tests/ILTransforms/Inlining.cs

18
ICSharpCode.Decompiler/IL/Instructions/Block.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.Decompiler.IL @@ -57,7 +57,7 @@ namespace ICSharpCode.Decompiler.IL
/// However, this is just of theoretical interest; we currently don't plan to use inline blocks that
/// pop elements that they didn't push themselves.
/// </remarks>
partial class Block : ILInstruction
partial class Block : ILInstruction, IEnumerable<ILInstruction>
{
public readonly InstructionCollection<ILInstruction> Instructions;
@ -150,5 +150,21 @@ namespace ICSharpCode.Decompiler.IL @@ -150,5 +150,21 @@ namespace ICSharpCode.Decompiler.IL
// an inline block has no phase-1 effects, so we're immediately done with inlining
return this;
}
// Add() and GetEnumerator() for collection initializer support:
public void Add(ILInstruction instruction)
{
this.Instructions.Add(instruction);
}
IEnumerator<ILInstruction> IEnumerable<ILInstruction>.GetEnumerator()
{
return this.Instructions.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.Instructions.GetEnumerator();
}
}
}

2
ICSharpCode.Decompiler/IL/SemanticHelper.cs

@ -22,6 +22,8 @@ namespace ICSharpCode.Decompiler.IL @@ -22,6 +22,8 @@ namespace ICSharpCode.Decompiler.IL
{
static class SemanticHelper
{
// TODO: consider moving IfInstruction.CombineFlags and Block.Phase1Boundary here
/// <summary>
/// Gets whether the instruction sequence 'inst1; inst2;' may be ordered to 'inst2; inst1;'
/// </summary>

3
ICSharpCode.Decompiler/Properties/AssemblyInfo.template.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#endregion
@ -25,3 +26,5 @@ using System.Runtime.InteropServices; @@ -25,3 +26,5 @@ using System.Runtime.InteropServices;
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly",
Justification = "AssemblyInformationalVersion does not need to be a parsable version")]
[assembly: InternalsVisibleTo("ICSharpCode.Decompiler.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf")]

51
ICSharpCode.Decompiler/Tests/Helpers/TypeSystemHelper.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// Copyright (c) 2015 Daniel Grunwald
//
// 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;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using Mono.Cecil;
namespace ICSharpCode.Decompiler.Tests.Helpers
{
/// <summary>
/// Helper class for building NRefactory type systems in test cases.
/// </summary>
public static class TypeSystem
{
static readonly Lazy<DecompilerTypeSystem> decompilerTypeSystem = new Lazy<DecompilerTypeSystem>(
delegate {
var module = ModuleDefinition.ReadModule(typeof(TypeSystem).Module.FullyQualifiedName);
return new DecompilerTypeSystem(module);
});
public static IAssembly FromReflection(Assembly assembly)
{
return decompilerTypeSystem.Value.Compilation.Assemblies.Single(asm => asm.AssemblyName == assembly.GetName().Name);
}
public static IType FromReflection(Type type)
{
return decompilerTypeSystem.Value.Compilation.FindType(type);
}
}
}

15
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -16,6 +16,11 @@ @@ -16,6 +16,11 @@
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<NoWarn>67,169,1058,728,1720,649</NoWarn>
<TargetFrameworkProfile />
<NoWin32Manifest>False</NoWin32Manifest>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\NRefactory\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile>
<DelaySign>False</DelaySign>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
@ -73,6 +78,10 @@ @@ -73,6 +78,10 @@
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\NRefactory\ICSharpCode.NRefactory.Cecil\ICSharpCode.NRefactory.Cecil.csproj">
<Project>{2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}</Project>
<Name>ICSharpCode.NRefactory.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
@ -87,10 +96,11 @@ @@ -87,10 +96,11 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="ExceptionHandling.cs" />
<Compile Include="Helpers\CodeAssert.cs" />
<Compile Include="Helpers\RemoveCompilerAttribute.cs" />
<Compile Include="Helpers\Tester.cs" />
<Compile Include="Helpers\TypeSystemHelper.cs" />
<Compile Include="ILTransforms\Inlining.cs" />
<Compile Include="TestCases\CompoundAssignment.cs" />
<Compile Include="TestCases\ControlFlow.cs" />
<Compile Include="TestCases\HelloWorld.cs" />
@ -100,5 +110,8 @@ @@ -100,5 +110,8 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Folder Include="ILTransforms" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

52
ICSharpCode.Decompiler/Tests/ILTransforms/Inlining.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// Copyright (c) 2014 Daniel Grunwald
//
// 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;
using ICSharpCode.Decompiler.IL;
using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.ILTransforms
{
/// <summary>
/// IL Inlining unit tests.
/// </summary>
public class Inlining
{
static ILFunction MakeFunction(ILInstruction body)
{
var f = new ILFunction(null, body);
f.AddRef();
return f;
}
[Test]
public void Simple()
{
var f = MakeFunction(
new Block {
new LdcI4(1),
new LdcI4(2),
new Add(new Pop(StackType.I4), new Pop(StackType.I4), false, Sign.Signed)
});
f.AcceptVisitor(new TransformingVisitor());
/*Assert.AreEqual(
,
f.Body
);*/
}
}
}
Loading…
Cancel
Save