diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index ac6e1c347..938378a19 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -81,6 +81,8 @@ namespace ICSharpCode.Decompiler.CSharp { if (Type.IsKnownType(KnownTypeCode.Boolean) || Type.Kind == TypeKind.Unknown) return Expression; + else if (Expression is PrimitiveExpression && Type.IsKnownType(KnownTypeCode.Int32)) + return new PrimitiveExpression((int)((PrimitiveExpression)Expression).Value != 0); else if (Type.Kind == TypeKind.Pointer) return new BinaryOperatorExpression(Expression, BinaryOperatorType.InEquality, new NullReferenceExpression()); else diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index cad2e879d..c75d9b2e8 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -58,6 +58,11 @@ namespace ICSharpCode.Decompiler.CSharp { return new EmptyStatement(); } + + protected internal override Statement VisitVoid(ICSharpCode.Decompiler.IL.Void inst) + { + return new ExpressionStatement(exprBuilder.Convert(inst.Argument)); + } protected internal override Statement VisitIfInstruction(IfInstruction inst) { diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index 95953d0a8..ed2024a53 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -120,6 +120,7 @@ namespace ICSharpCode.Decompiler.IL if (outputStacks != null) outputStacks.Add(start, stack.ToImmutableArray()); ILInstruction decodedInstruction = DecodeInstruction(); + decodedInstruction.CheckInvariant(); if (decodedInstruction.ResultType != StackType.Void) stack.Push(decodedInstruction.ResultType); decodedInstruction.ILRange = new Interval(start, reader.Position); diff --git a/ICSharpCode.Decompiler/IL/ILTypeExtensions.cs b/ICSharpCode.Decompiler/IL/ILTypeExtensions.cs index bdf1a297d..8340ff320 100644 --- a/ICSharpCode.Decompiler/IL/ILTypeExtensions.cs +++ b/ICSharpCode.Decompiler/IL/ILTypeExtensions.cs @@ -45,7 +45,12 @@ namespace ICSharpCode.Decompiler.IL public static StackType GetStackType(this TypeReference typeRef) { - return typeRef.SkipModifiers().MetadataType.GetStackType(); + typeRef = typeRef.SkipModifiers(); + TypeDefinition typeDef = typeRef.Resolve(); + if (typeDef != null && typeDef.IsEnum) { + typeRef = typeDef.GetEnumUnderlyingType(); + } + return typeRef.MetadataType.GetStackType(); } public static TypeReference SkipModifiers(this TypeReference typeRef) diff --git a/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs b/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs index 3977c5a00..833746d3c 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/IfInstruction.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; namespace ICSharpCode.Decompiler.IL { @@ -30,6 +31,12 @@ namespace ICSharpCode.Decompiler.IL this.FalseInst = falseInst ?? new Nop(); } + internal override void CheckInvariant() + { + base.CheckInvariant(); + Debug.Assert(condition.ResultType == StackType.I4); + } + public override StackType ResultType { get { return CommonResultType(trueInst.ResultType, falseInst.ResultType);