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. 2
      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 @@
<Compile Include="FlowAnalysis\SsaOptimization.cs" /> <Compile Include="FlowAnalysis\SsaOptimization.cs" />
<Compile Include="FlowAnalysis\SsaVariable.cs" /> <Compile Include="FlowAnalysis\SsaVariable.cs" />
<Compile Include="FlowAnalysis\TransformToSsa.cs" /> <Compile Include="FlowAnalysis\TransformToSsa.cs" />
<Compile Include="ILAst\NullableOperators.cs" /> <Compile Include="ILAst\LiftedOperators.cs" />
<Compile Include="ILAst\InitializerPeepholeTransforms.cs" /> <Compile Include="ILAst\InitializerPeepholeTransforms.cs" />
<Compile Include="ILAst\DefaultDictionary.cs" /> <Compile Include="ILAst\DefaultDictionary.cs" />
<Compile Include="ILAst\GotoRemoval.cs" /> <Compile Include="ILAst\GotoRemoval.cs" />

6
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

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

2
ICSharpCode.Decompiler/ILAst/ILCodes.cs

@ -317,7 +317,7 @@ 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(...))" /// Also used when inlining a method call on a value type: "stloc(v, ...); call(M, ldloca(v));" becomes "call(M, AddressOf(...))"
/// </remarks> /// </remarks>
AddressOf, 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> /// <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(...), ...))" /// 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> /// </remarks>

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

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

8
ICSharpCode.Decompiler/ILAst/PeepholeTransform.cs

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

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

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

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

@ -19,9 +19,9 @@
using System; using System;
using System.Runtime.InteropServices; 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. // 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. // 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. // A comparison used in a condition differs somewhat from a comparison used as a simple value.
@ -131,7 +131,7 @@ public static class NullableOperators
a ^= b; 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());
Console.WriteLine(a != x()); Console.WriteLine(a != x());
@ -151,7 +151,7 @@ public static class NullableOperators
a ^= x(); a ^= x();
Console.WriteLine(x() ^ a); Console.WriteLine(x() ^ a);
list[0] ^= x(); (new bool?[0])[0] ^= x();
} }
public static void BoolValueConst(bool? a) public static void BoolValueConst(bool? a)
@ -316,7 +316,7 @@ public static class NullableOperators
a >>= b; 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());
Console.WriteLine(a != x()); Console.WriteLine(a != x());
@ -349,7 +349,7 @@ public static class NullableOperators
a >>= x(); a >>= x();
Console.WriteLine(x() + a); Console.WriteLine(x() + a);
list[0] += x(); (new int?[0])[0] += x();
} }
public static void IntValueConst(int? a) public static void IntValueConst(int? a)
@ -515,7 +515,7 @@ public static class NullableOperators
a %= b; 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());
Console.WriteLine(a != x()); Console.WriteLine(a != x());
@ -538,7 +538,7 @@ public static class NullableOperators
a %= x(); a %= x();
Console.WriteLine(x() + a); Console.WriteLine(x() + a);
list[0] += x(); (new decimal?[0])[0] += x();
} }
public static void NumberValueConst(decimal? a) public static void NumberValueConst(decimal? a)
@ -679,7 +679,7 @@ public static class NullableOperators
a >>= i; 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());
Console.WriteLine(a != x()); Console.WriteLine(a != x());
@ -712,7 +712,7 @@ public static class NullableOperators
a >>= i(); a >>= i();
Console.WriteLine(x() + a); Console.WriteLine(x() + a);
list[0] += x(); (new TS?[0])[0] += x();
} }
} }

12
ICSharpCode.Decompiler/Tests/TestRunner.cs

@ -83,21 +83,21 @@ namespace ICSharpCode.Decompiler.Tests
} }
[Test] [Test]
public void Loops() public void LiftedOperators()
{ {
TestFile(@"..\..\Tests\Loops.cs"); TestFile(@"..\..\Tests\LiftedOperators.cs");
} }
[Test] [Test]
public void MultidimensionalArray() public void Loops()
{ {
TestFile(@"..\..\Tests\MultidimensionalArray.cs"); TestFile(@"..\..\Tests\Loops.cs");
} }
[Test] [Test]
public void NullableOperators() public void MultidimensionalArray()
{ {
TestFile(@"..\..\Tests\NullableOperators.cs"); TestFile(@"..\..\Tests\MultidimensionalArray.cs");
} }
[Test] [Test]

Loading…
Cancel
Save