Browse Source

Threat stloc as expression that returns value (the stored value)

pull/37/head
David Srbecký 15 years ago
parent
commit
77d1f62356
  1. 23
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs
  2. 3
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

23
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -468,16 +468,25 @@ namespace Decompiler @@ -468,16 +468,25 @@ namespace Decompiler
// We are moving the expression evaluation past the other aguments.
// It is ok to pass ldloc because the expression can not contain stloc and thus the ldcoc will still return the same value
if (arg.Code == ILCode.Ldloc) {
bool canInline;
allowInline.TryGetValue((ILVariable)arg.Operand, out canInline);
if (arg.Operand == currExpr.Operand && canInline) {
if (arg.Operand == currExpr.Operand) {
bool canInline;
allowInline.TryGetValue((ILVariable)arg.Operand, out canInline);
// Assigne the ranges for optimized away instrustions somewhere
currExpr.Arguments[0].ILRanges.AddRange(currExpr.ILRanges);
currExpr.Arguments[0].ILRanges.AddRange(nextExpr.Arguments[j].ILRanges);
ast.RemoveAt(i);
nextExpr.Arguments[j] = currExpr.Arguments[0]; // Inline the stloc body
i -= 2; // Try the same index again
break; // Found
if (canInline) {
ast.RemoveAt(i);
nextExpr.Arguments[j] = currExpr.Arguments[0]; // Inline the stloc body
i -= 2; // Try the same index again
break; // Found
} else {
ast.RemoveAt(i);
nextExpr.Arguments[j] = currExpr; // Inline the whole stloc
i -= 2; // Try the same index again
break; // Found
}
}
} else {
break; // Side-effects

3
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -127,9 +127,10 @@ namespace Decompiler @@ -127,9 +127,10 @@ namespace Decompiler
TypeReference t = InferTypeForExpression(expr.Arguments.Single(), ((ILVariable)expr.Operand).Type);
if (v.Type == null)
v.Type = t;
return t;
}
return null;
}
return null;
case Code.Ldloc:
{
ILVariable v = (ILVariable)expr.Operand;

Loading…
Cancel
Save