Browse Source

Use consistent terminology for lifted operators

pull/205/head
Pent Ploompuu 14 years ago
parent
commit
92c892577d
  1. 2
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  2. 6
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  3. 4
      ICSharpCode.Decompiler/ILAst/ILCodes.cs
  4. 8
      ICSharpCode.Decompiler/ILAst/LiftedOperators.cs
  5. 8
      ICSharpCode.Decompiler/ILAst/PeepholeTransform.cs
  6. 2
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj
  7. 20
      ICSharpCode.Decompiler/Tests/LiftedOperators.cs
  8. 12
      ICSharpCode.Decompiler/Tests/TestRunner.cs

2
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -95,7 +95,7 @@ @@ -95,7 +95,7 @@
<Compile Include="FlowAnalysis\SsaOptimization.cs" />
<Compile Include="FlowAnalysis\SsaVariable.cs" />
<Compile Include="FlowAnalysis\TransformToSsa.cs" />
<Compile Include="ILAst\NullableOperators.cs" />
<Compile Include="ILAst\LiftedOperators.cs" />
<Compile Include="ILAst\InitializerPeepholeTransforms.cs" />
<Compile Include="ILAst\DefaultDictionary.cs" />
<Compile Include="ILAst\GotoRemoval.cs" />

6
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.ILAst
TransformDecimalCtorToConstant,
SimplifyLdObjAndStObj,
SimplifyCustomShortCircuit,
SimplifyNullableOperators,
SimplifyLiftedOperators,
TransformArrayInitializers,
TransformMultidimensionalArrayInitializers,
TransformObjectInitializers,
@ -152,8 +152,8 @@ namespace ICSharpCode.Decompiler.ILAst @@ -152,8 +152,8 @@ namespace ICSharpCode.Decompiler.ILAst
if (abortBeforeStep == ILAstOptimizationStep.SimplifyCustomShortCircuit) return;
modified |= block.RunOptimization(new SimpleControlFlow(context, method).SimplifyCustomShortCircuit);
if (abortBeforeStep == ILAstOptimizationStep.SimplifyNullableOperators) return;
modified |= block.RunOptimization(SimplifyNullableOperators);
if (abortBeforeStep == ILAstOptimizationStep.SimplifyLiftedOperators) return;
modified |= block.RunOptimization(SimplifyLiftedOperators);
if (abortBeforeStep == ILAstOptimizationStep.TransformArrayInitializers) return;
modified |= block.RunOptimization(TransformArrayInitializers);

4
ICSharpCode.Decompiler/ILAst/ILCodes.cs

@ -317,12 +317,12 @@ namespace ICSharpCode.Decompiler.ILAst @@ -317,12 +317,12 @@ namespace ICSharpCode.Decompiler.ILAst
/// Also used when inlining a method call on a value type: "stloc(v, ...); call(M, ldloca(v));" becomes "call(M, AddressOf(...))"
/// </remarks>
AddressOf,
/// <summary>Simulates getting the value of the nullable argument in comparisons involving nullable values</summary>
/// <summary>Simulates getting the value of a lifted operator's nullable argument</summary>
/// <remarks>
/// For example "stloc(v1, ...); stloc(v2, ...); logicand(ceq(call(Nullable`1::GetValueOrDefault, ldloca(v1)), ldloc(v2)), callgetter(Nullable`1::get_HasValue, ldloca(v1)))" becomes "wrap(ceq(ValueOf(...), ...))"
/// </remarks>
ValueOf,
/// <summary>Simulates creating a new nullable value from a valuetype argument</summary>
/// <summary>Simulates creating a new nullable value from a value type argument</summary>
/// <remarks>
/// For example "stloc(v1, ...); stloc(v2, ...); ternaryop(callgetter(Nullable`1::get_HasValue, ldloca(v1)), newobj(Nullable`1::.ctor, add(call(Nullable`1::GetValueOrDefault, ldloca(v1)), ldloc(v2))), defaultvalue(Nullable`1))"
/// becomes "NullableOf(add(valueof(...), ...))"

8
ICSharpCode.Decompiler/ILAst/NullableOperators.cs → ICSharpCode.Decompiler/ILAst/LiftedOperators.cs

@ -26,9 +26,9 @@ namespace ICSharpCode.Decompiler.ILAst @@ -26,9 +26,9 @@ namespace ICSharpCode.Decompiler.ILAst
{
partial class ILAstOptimizer
{
bool SimplifyNullableOperators(List<ILNode> body, ILExpression expr, int pos)
bool SimplifyLiftedOperators(List<ILNode> body, ILExpression expr, int pos)
{
if (!new PatternMatcher(typeSystem).SimplifyNullableOperators(expr)) return false;
if (!new PatternMatcher(typeSystem).SimplifyLiftedOperators(expr)) return false;
var inlining = new ILInlining(method);
while (--pos >= 0 && inlining.InlineIfPossible(body, ref pos)) ;
@ -44,13 +44,13 @@ namespace ICSharpCode.Decompiler.ILAst @@ -44,13 +44,13 @@ namespace ICSharpCode.Decompiler.ILAst
this.typeSystem = typeSystem;
}
public bool SimplifyNullableOperators(ILExpression expr)
public bool SimplifyLiftedOperators(ILExpression expr)
{
if (Simplify(expr)) return true;
bool modified = false;
foreach (var a in expr.Arguments)
modified |= SimplifyNullableOperators(a);
modified |= SimplifyLiftedOperators(a);
return modified;
}

8
ICSharpCode.Decompiler/ILAst/PeepholeTransform.cs

@ -397,17 +397,17 @@ namespace ICSharpCode.Decompiler.ILAst @@ -397,17 +397,17 @@ namespace ICSharpCode.Decompiler.ILAst
return false;
ILExpression op = expr.Arguments.Last();
// in case of compound assignments with nullable values the result is inside NullableOf and the operand is inside ValueOf
bool nullable = false;
// in case of compound assignments with a lifted operator the result is inside NullableOf and the operand is inside ValueOf
bool liftedOperator = false;
if (op.Code == ILCode.NullableOf) {
op = op.Arguments[0];
nullable = true;
liftedOperator = true;
}
if (!CanBeRepresentedAsCompoundAssignment(op))
return false;
ILExpression ldelem = op.Arguments[0];
if (nullable) {
if (liftedOperator) {
if (ldelem.Code != ILCode.ValueOf)
return false;
ldelem = ldelem.Arguments[0];

2
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -64,7 +64,7 @@ @@ -64,7 +64,7 @@
<ItemGroup>
<Compile Include="CallOverloadedMethod.cs" />
<Compile Include="CheckedUnchecked.cs" />
<Compile Include="NullableOperators.cs" />
<Compile Include="LiftedOperators.cs" />
<Compile Include="CustomShortCircuitOperators.cs" />
<Compile Include="Helpers\CodeAssert.cs" />
<Compile Include="IncrementDecrement.cs" />

20
ICSharpCode.Decompiler/Tests/NullableOperators.cs → ICSharpCode.Decompiler/Tests/LiftedOperators.cs

@ -19,9 +19,9 @@ @@ -19,9 +19,9 @@
using System;
using System.Runtime.InteropServices;
public static class NullableOperators
public static class LiftedOperators
{
// C# uses 4 different patterns of IL for operators involving nullable values: bool, other primitive types, decimal, other structs.
// C# uses 4 different patterns of IL for lifted operators: bool, other primitive types, decimal, other structs.
// Different patterns are used depending on whether both of the operands are nullable or only the left/right operand is nullable.
// Negation must not be pushed through such comparisons because it would change the semantics.
// A comparison used in a condition differs somewhat from a comparison used as a simple value.
@ -131,7 +131,7 @@ public static class NullableOperators @@ -131,7 +131,7 @@ public static class NullableOperators
a ^= b;
}
public static void BoolValueComplex(bool? a, Func<bool> x, bool?[] list)
public static void BoolValueComplex(bool? a, Func<bool> x)
{
Console.WriteLine(a == x());
Console.WriteLine(a != x());
@ -151,7 +151,7 @@ public static class NullableOperators @@ -151,7 +151,7 @@ public static class NullableOperators
a ^= x();
Console.WriteLine(x() ^ a);
list[0] ^= x();
(new bool?[0])[0] ^= x();
}
public static void BoolValueConst(bool? a)
@ -316,7 +316,7 @@ public static class NullableOperators @@ -316,7 +316,7 @@ public static class NullableOperators
a >>= b;
}
public static void IntValueComplex(int? a, Func<int> x, int?[] list)
public static void IntValueComplex(int? a, Func<int> x)
{
Console.WriteLine(a == x());
Console.WriteLine(a != x());
@ -349,7 +349,7 @@ public static class NullableOperators @@ -349,7 +349,7 @@ public static class NullableOperators
a >>= x();
Console.WriteLine(x() + a);
list[0] += x();
(new int?[0])[0] += x();
}
public static void IntValueConst(int? a)
@ -515,7 +515,7 @@ public static class NullableOperators @@ -515,7 +515,7 @@ public static class NullableOperators
a %= b;
}
public static void NumberValueComplex(decimal? a, Func<decimal> x, decimal?[] list)
public static void NumberValueComplex(decimal? a, Func<decimal> x)
{
Console.WriteLine(a == x());
Console.WriteLine(a != x());
@ -538,7 +538,7 @@ public static class NullableOperators @@ -538,7 +538,7 @@ public static class NullableOperators
a %= x();
Console.WriteLine(x() + a);
list[0] += x();
(new decimal?[0])[0] += x();
}
public static void NumberValueConst(decimal? a)
@ -679,7 +679,7 @@ public static class NullableOperators @@ -679,7 +679,7 @@ public static class NullableOperators
a >>= i;
}
public static void StructValueComplex(TS? a, Func<TS> x, Func<int> i, TS?[] list)
public static void StructValueComplex(TS? a, Func<TS> x, Func<int> i)
{
Console.WriteLine(a == x());
Console.WriteLine(a != x());
@ -712,7 +712,7 @@ public static class NullableOperators @@ -712,7 +712,7 @@ public static class NullableOperators
a >>= i();
Console.WriteLine(x() + a);
list[0] += x();
(new TS?[0])[0] += x();
}
}

12
ICSharpCode.Decompiler/Tests/TestRunner.cs

@ -80,6 +80,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -80,6 +80,12 @@ namespace ICSharpCode.Decompiler.Tests
public void InitializerTests()
{
TestFile(@"..\..\Tests\InitializerTests.cs");
}
[Test]
public void LiftedOperators()
{
TestFile(@"..\..\Tests\LiftedOperators.cs");
}
[Test]
@ -93,12 +99,6 @@ namespace ICSharpCode.Decompiler.Tests @@ -93,12 +99,6 @@ namespace ICSharpCode.Decompiler.Tests
{
TestFile(@"..\..\Tests\MultidimensionalArray.cs");
}
[Test]
public void NullableOperators()
{
TestFile(@"..\..\Tests\NullableOperators.cs");
}
[Test]
public void PInvoke()

Loading…
Cancel
Save