mirror of https://github.com/icsharpcode/ILSpy.git
13 changed files with 240 additions and 16 deletions
@ -0,0 +1,100 @@ |
|||||||
|
// 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 System.Diagnostics; |
||||||
|
using ICSharpCode.Decompiler.IL; |
||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.Decompiler.Tests.Helpers; |
||||||
|
|
||||||
|
namespace ICSharpCode.Decompiler.Tests.ILTransforms |
||||||
|
{ |
||||||
|
public class IntervalTests |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void DefaultIsEmpty() |
||||||
|
{ |
||||||
|
Assert.IsTrue(default(Interval).IsEmpty); |
||||||
|
Assert.IsFalse(default(Interval).Contains(-1)); |
||||||
|
Assert.IsFalse(default(Interval).Contains(0)); |
||||||
|
Assert.IsFalse(default(Interval).Contains(1)); |
||||||
|
} |
||||||
|
[Test] |
||||||
|
public void EmptyAt1() |
||||||
|
{ |
||||||
|
Interval i = new Interval(1, 1); |
||||||
|
Assert.IsTrue(default(Interval).IsEmpty); |
||||||
|
Assert.IsFalse(default(Interval).Contains(-1)); |
||||||
|
Assert.IsFalse(default(Interval).Contains(0)); |
||||||
|
Assert.IsFalse(default(Interval).Contains(1)); |
||||||
|
Assert.IsFalse(default(Interval).Contains(2)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void OneToThree() |
||||||
|
{ |
||||||
|
Interval i = new Interval(1, 3); |
||||||
|
Assert.IsFalse(i.IsEmpty); |
||||||
|
Assert.IsFalse(i.Contains(0)); |
||||||
|
Assert.IsTrue(i.Contains(1)); |
||||||
|
Assert.IsTrue(i.Contains(2)); |
||||||
|
Assert.IsFalse(i.Contains(3)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FullInterval() |
||||||
|
{ |
||||||
|
Interval full = new Interval(int.MinValue, int.MinValue); |
||||||
|
Assert.IsFalse(full.IsEmpty); |
||||||
|
Assert.IsTrue(full.Contains(int.MinValue)); |
||||||
|
Assert.IsTrue(full.Contains(0)); |
||||||
|
Assert.IsTrue(full.Contains(int.MaxValue)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NonNegativeIntegers() |
||||||
|
{ |
||||||
|
Interval i = new Interval(0, int.MinValue); |
||||||
|
Assert.IsFalse(i.IsEmpty); |
||||||
|
Assert.IsTrue(i.Contains(0)); |
||||||
|
Assert.IsTrue(i.Contains(1000)); |
||||||
|
Assert.IsTrue(i.Contains(int.MaxValue)); |
||||||
|
Assert.IsFalse(i.Contains(-1)); |
||||||
|
Assert.IsFalse(i.Contains(-1000)); |
||||||
|
Assert.IsFalse(i.Contains(int.MinValue)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Intersection() |
||||||
|
{ |
||||||
|
Interval empty = new Interval(0, 0); |
||||||
|
Interval emptyAtOne = new Interval(0, 0); |
||||||
|
Interval zero = new Interval(0, 1); |
||||||
|
Interval full = new Interval(int.MinValue, int.MinValue); |
||||||
|
Interval nonneg = new Interval(0, int.MinValue); |
||||||
|
Interval nonpos = new Interval(int.MinValue, 1); |
||||||
|
Interval maxval = new Interval(int.MaxValue, int.MinValue); |
||||||
|
Assert.AreEqual(nonneg, full.Intersect(nonneg)); |
||||||
|
Assert.AreEqual(nonneg, nonneg.Intersect(full)); |
||||||
|
Assert.AreEqual(zero, nonneg.Intersect(zero)); |
||||||
|
Assert.AreEqual(zero, nonneg.Intersect(nonpos)); |
||||||
|
Assert.AreEqual(maxval, nonneg.Intersect(maxval)); |
||||||
|
Assert.AreEqual(empty, nonpos.Intersect(maxval)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
// 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.NRefactory.TypeSystem; |
||||||
|
using Mono.Cecil; |
||||||
|
|
||||||
|
namespace ICSharpCode.Decompiler |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Allows resolving cecil types into the NRefactory type system.
|
||||||
|
/// </summary>
|
||||||
|
public interface IDecompilerTypeSystem |
||||||
|
{ |
||||||
|
ICompilation Compilation { get; } |
||||||
|
|
||||||
|
IType Resolve(TypeReference typeReference); |
||||||
|
IField Resolve(FieldReference fieldReference); |
||||||
|
IMethod Resolve(MethodReference methodReference); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,67 @@ |
|||||||
|
// 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.NRefactory.TypeSystem; |
||||||
|
|
||||||
|
namespace ICSharpCode.Decompiler |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Decompiler type system for generic types or methods:
|
||||||
|
/// used to replace the dummy type parameters by the actual type parameters of the method being decompiled.
|
||||||
|
/// </summary>
|
||||||
|
public class SpecializingDecompilerTypeSystem : IDecompilerTypeSystem |
||||||
|
{ |
||||||
|
readonly IDecompilerTypeSystem context; |
||||||
|
readonly TypeParameterSubstitution substitution; |
||||||
|
|
||||||
|
public SpecializingDecompilerTypeSystem(IDecompilerTypeSystem context, TypeParameterSubstitution substitution) |
||||||
|
{ |
||||||
|
if (context == null) |
||||||
|
throw new ArgumentNullException("context"); |
||||||
|
if (substitution == null) |
||||||
|
throw new ArgumentNullException("substitution"); |
||||||
|
this.context = context; |
||||||
|
this.substitution = substitution; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompilation Compilation { |
||||||
|
get { return context.Compilation; } |
||||||
|
} |
||||||
|
|
||||||
|
public IType Resolve(Mono.Cecil.TypeReference typeReference) |
||||||
|
{ |
||||||
|
return context.Resolve(typeReference).AcceptVisitor(substitution); |
||||||
|
} |
||||||
|
|
||||||
|
public IField Resolve(Mono.Cecil.FieldReference fieldReference) |
||||||
|
{ |
||||||
|
IField field = context.Resolve(fieldReference); |
||||||
|
if (field != null) |
||||||
|
field = (IField)field.Specialize(substitution); |
||||||
|
return field; |
||||||
|
} |
||||||
|
|
||||||
|
public IMethod Resolve(Mono.Cecil.MethodReference methodReference) |
||||||
|
{ |
||||||
|
IMethod method = context.Resolve(methodReference); |
||||||
|
if (method != null) |
||||||
|
method = (IMethod)method.Specialize(substitution); |
||||||
|
return method; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue