Browse Source

output LongLength or Length for ldlen depending on expected result type

pull/728/head
Siegfried Pammer 10 years ago
parent
commit
3b5cb4e5c7
  1. 19
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

19
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -351,12 +351,10 @@ namespace ICSharpCode.Decompiler.CSharp
// Ensure the inputs have the correct sign: // Ensure the inputs have the correct sign:
KnownTypeCode inputType = KnownTypeCode.None; KnownTypeCode inputType = KnownTypeCode.None;
switch (inst.OpType) { switch (inst.OpType) {
case StackType.I: // In order to generate valid C# we need to treat (U)IntPtr as (U)Int64 in comparisons.
case StackType.I8: case StackType.I8:
inputType = un ? KnownTypeCode.UInt64 : KnownTypeCode.Int64; inputType = un ? KnownTypeCode.UInt64 : KnownTypeCode.Int64;
break; break;
case StackType.I:
inputType = un ? KnownTypeCode.UIntPtr : KnownTypeCode.IntPtr;
break;
case StackType.I4: case StackType.I4:
inputType = un ? KnownTypeCode.UInt32 : KnownTypeCode.Int32; inputType = un ? KnownTypeCode.UInt32 : KnownTypeCode.Int32;
break; break;
@ -739,10 +737,17 @@ namespace ICSharpCode.Decompiler.CSharp
if (arrayExpr.Type.Kind != TypeKind.Array) { if (arrayExpr.Type.Kind != TypeKind.Array) {
arrayExpr = arrayExpr.ConvertTo(compilation.FindType(KnownTypeCode.Array), this); arrayExpr = arrayExpr.ConvertTo(compilation.FindType(KnownTypeCode.Array), this);
} }
var lenExpr = arrayExpr.Expression.Member("LongLength") TranslatedExpression lenExpr;
.WithILInstruction(inst) if (inst.ResultType == StackType.I4) {
.WithRR(new ResolveResult(compilation.FindType(KnownTypeCode.Int64))); lenExpr = arrayExpr.Expression.Member("Length")
return lenExpr.ConvertTo(compilation.FindType(KnownTypeCode.UIntPtr), this); .WithILInstruction(inst)
.WithRR(new ResolveResult(compilation.FindType(KnownTypeCode.Int32)));
} else {
lenExpr = arrayExpr.Expression.Member("LongLength")
.WithILInstruction(inst)
.WithRR(new ResolveResult(compilation.FindType(KnownTypeCode.Int64)));
}
return lenExpr.ConvertTo(compilation.FindType(inst.ResultType.ToKnownTypeCode()), this);
} }
protected internal override TranslatedExpression VisitLdFlda(LdFlda inst) protected internal override TranslatedExpression VisitLdFlda(LdFlda inst)

Loading…
Cancel
Save