Browse Source

Use ILVariable as ldloca operand.

pull/37/head
Daniel Grunwald 15 years ago
parent
commit
8b342ea469
  1. 12
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 9
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs
  3. 2
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

12
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -608,17 +608,9 @@ namespace Decompiler @@ -608,17 +608,9 @@ namespace Decompiler
AstBuilder.ConvertType(((FieldReference)operand).DeclaringType)
.Member(((FieldReference)operand).Name).WithAnnotation(operand));
case Code.Ldloc:
if (operand is ILVariable) {
return new Ast.IdentifierExpression(((ILVariable)operand).Name);
} else {
return new Ast.IdentifierExpression(((VariableDefinition)operand).Name);
}
return new Ast.IdentifierExpression(((ILVariable)operand).Name);
case Code.Ldloca:
if (operand is ILVariable) {
return MakeRef(new Ast.IdentifierExpression(((ILVariable)operand).Name));
} else {
return MakeRef(new Ast.IdentifierExpression(((VariableDefinition)operand).Name));
}
return MakeRef(new Ast.IdentifierExpression(((ILVariable)operand).Name));
case Code.Ldnull: return new Ast.NullReferenceExpression();
case Code.Ldobj: throw new NotImplementedException();
case Code.Ldstr: return new Ast.PrimitiveExpression(operand);

9
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -262,11 +262,16 @@ namespace Decompiler @@ -262,11 +262,16 @@ namespace Decompiler
int index = ((VariableDefinition)byteCode.Operand).Index;
byteCode.Operand = Variables[index];
numReads[index]++;
}
if (byteCode.Code == ILCode.Stloc) {
} else if (byteCode.Code == ILCode.Stloc) {
int index = ((VariableDefinition)byteCode.Operand).Index;
byteCode.Operand = Variables[index];
numWrites[index]++;
} else if (byteCode.Code == ILCode.Ldloca) {
int index = ((VariableDefinition)byteCode.Operand).Index;
byteCode.Operand = Variables[index];
// ldloca leads to an unknown numbers of reads/writes, so ensure we don't inline the variable
numReads[index] += 2;
numWrites[index] += 2;
}
}

2
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -85,7 +85,7 @@ namespace Decompiler @@ -85,7 +85,7 @@ namespace Decompiler
case Code.Ldarg:
return ((ParameterReference)expr.Operand).ParameterType;
case Code.Ldloca:
return new ByReferenceType(((VariableDefinition)expr.Operand).VariableType);
return new ByReferenceType(((ILVariable)expr.Operand).Type);
case Code.Ldarga:
return new ByReferenceType(((ParameterReference)expr.Operand).ParameterType);
#endregion

Loading…
Cancel
Save