Browse Source

Amend of last commit - remove stloc only if the inner expression is valid expression statement and the variable is generated

pull/100/head
David Srbecký 14 years ago
parent
commit
892297708f
  1. 17
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  2. 5
      ICSharpCode.Decompiler/ILAst/ILInlining.cs

17
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -1069,6 +1069,23 @@ namespace ICSharpCode.Decompiler.ILAst @@ -1069,6 +1069,23 @@ namespace ICSharpCode.Decompiler.ILAst
}
}
/// <summary>
/// Can the expression be used as a statement in C#?
/// </summary>
public static bool CanBeExpressionStatement(this ILExpression expr)
{
switch(expr.Code) {
case ILCode.Call:
case ILCode.Calli:
case ILCode.Callvirt:
case ILCode.Newobj:
case ILCode.Newarr:
return true;
default:
return false;
}
}
public static V GetOrDefault<K,V>(this Dictionary<K, V> dict, K key)
{
V ret;

5
ICSharpCode.Decompiler/ILAst/ILInlining.cs

@ -138,13 +138,14 @@ namespace ICSharpCode.Decompiler.ILAst @@ -138,13 +138,14 @@ namespace ICSharpCode.Decompiler.ILAst
if (inlinedExpression.HasNoSideEffects()) {
// Remove completely
block.Body.RemoveAt(pos);
} else {
return true;
} else if (inlinedExpression.CanBeExpressionStatement() && v.IsGenerated) {
// Assign the ranges of the stloc instruction:
inlinedExpression.ILRanges.AddRange(((ILExpression)block.Body[pos]).ILRanges);
// Remove the stloc, but keep the inner expression
block.Body[pos] = inlinedExpression;
return true;
}
return true;
}
}
return false;

Loading…
Cancel
Save