Browse Source

implement StObj instruction

pull/728/head
Siegfried Pammer 11 years ago
parent
commit
7f36725b6f
  1. 2
      ICSharpCode.Decompiler/CSharp/ConvertedExpression.cs
  2. 21
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 10
      ICSharpCode.Decompiler/Tests/TestCases/ControlFlow.cs

2
ICSharpCode.Decompiler/CSharp/ConvertedExpression.cs

@ -148,7 +148,7 @@ namespace ICSharpCode.Decompiler.CSharp
foreach (var inst in parent.Annotations.OfType<ILInstruction>()) foreach (var inst in parent.Annotations.OfType<ILInstruction>())
descendant.AddAnnotation(inst); descendant.AddAnnotation(inst);
if (parent == Expression) if (parent == Expression)
return new ConvertedExpression(descendant); return new ConvertedExpression(descendant.Detach());
} }
throw new ArgumentException("descendant must be a descendant of the current node"); throw new ArgumentException("descendant must be a descendant of the current node");
} }

21
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -450,7 +450,26 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(new ResolveResult(type)); .WithRR(new ResolveResult(type));
} }
} }
protected internal override ConvertedExpression VisitStObj(StObj inst)
{
var target = Convert(inst.Target);
var value = Convert(inst.Value);
var type = cecilMapper.GetType(inst.Type);
ConvertedExpression result;
if (target.Type.Equals(new ByReferenceType(type)) && target.Expression is DirectionExpression) {
// we can deference the managed reference by stripping away the 'ref'
result = target.UnwrapChild(((DirectionExpression)target.Expression).Expression);
} else {
// Cast pointer type if necessary:
target = target.ConvertTo(new PointerType(type), this);
result = new UnaryOperatorExpression(UnaryOperatorType.Dereference, target.Expression)
.WithoutILInstruction()
.WithRR(new ResolveResult(type));
}
return Assignment(result, value).WithILInstruction(inst);
}
protected internal override ConvertedExpression VisitUnboxAny(UnboxAny inst) protected internal override ConvertedExpression VisitUnboxAny(UnboxAny inst)
{ {
var arg = Convert(inst.Argument); var arg = Convert(inst.Argument);

10
ICSharpCode.Decompiler/Tests/TestCases/ControlFlow.cs

@ -41,7 +41,7 @@ class ControlFlow
{ {
if (input.Contains("test")) { if (input.Contains("test")) {
} }
result++; result = result + 1;
Console.WriteLine("EmptyIf"); Console.WriteLine("EmptyIf");
} }
@ -52,7 +52,7 @@ class ControlFlow
} else { } else {
Console.WriteLine("else"); Console.WriteLine("else");
} }
result++; result = result + 1;
Console.WriteLine("end"); Console.WriteLine("end");
} }
@ -61,7 +61,7 @@ class ControlFlow
if (input.Contains("test")) { if (input.Contains("test")) {
Console.WriteLine("result"); Console.WriteLine("result");
} }
result++; result = result + 1;
Console.WriteLine("end"); Console.WriteLine("end");
} }
@ -72,14 +72,14 @@ class ControlFlow
} else { } else {
Console.WriteLine("else"); Console.WriteLine("else");
} }
result++; result = result + 1;
} }
static void Test(string input, ref int result) static void Test(string input, ref int result)
{ {
foreach (char c in input) { foreach (char c in input) {
Console.Write(c); Console.Write(c);
result++; result = result + 1;
} }
if (input.Contains("test")) { if (input.Contains("test")) {
Console.WriteLine("result"); Console.WriteLine("result");

Loading…
Cancel
Save