From ad8d4a7ef64e01dbe90dce08f7e33be7b2d1e480 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 9 Mar 2015 22:05:47 +0100 Subject: [PATCH] Fix duplicate ResolveResult on ConvertConstantValue() --- ICSharpCode.Decompiler/CSharp/Annotations.cs | 7 +++++++ .../CSharp/ExpressionBuilder.cs | 15 +++++++++++++-- .../CSharp/TranslatedExpression.cs | 5 ++--- ILSpy/Properties/app.config.template | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/Annotations.cs b/ICSharpCode.Decompiler/CSharp/Annotations.cs index cc43a9f6e..a522a67b0 100644 --- a/ICSharpCode.Decompiler/CSharp/Annotations.cs +++ b/ICSharpCode.Decompiler/CSharp/Annotations.cs @@ -57,6 +57,13 @@ namespace ICSharpCode.Decompiler.CSharp return new TranslatedExpression(expression.Expression, expression.ResolveResult); } + public static TranslatedExpression WithILInstruction(this ExpressionWithResolveResult expression, IEnumerable instructions) + { + foreach (var inst in instructions) + expression.Expression.AddAnnotation(inst); + return new TranslatedExpression(expression.Expression, expression.ResolveResult); + } + public static TranslatedExpression WithoutILInstruction(this ExpressionWithResolveResult expression) { return new TranslatedExpression(expression.Expression, expression.ResolveResult); diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 0172d53ea..61d0b15ac 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.CSharp { internal readonly ICompilation compilation; internal readonly CSharpResolver resolver; - internal readonly TypeSystemAstBuilder astBuilder; + readonly TypeSystemAstBuilder astBuilder; public ExpressionBuilder(ITypeResolveContext decompilationContext) { @@ -55,10 +55,21 @@ namespace ICSharpCode.Decompiler.CSharp public AstType ConvertType(IType type) { var astType = astBuilder.ConvertType(type); - astType.AddAnnotation(new TypeResolveResult(type)); + Debug.Assert(astType.Annotation() != null); return astType; } + public ExpressionWithResolveResult ConvertConstantValue(ResolveResult rr) + { + var expr = astBuilder.ConvertConstantValue(rr); + var exprRR = expr.Annotation(); + if (exprRR == null) { + exprRR = rr; + expr.AddAnnotation(rr); + } + return new ExpressionWithResolveResult(expr, exprRR); + } + public TranslatedExpression Translate(ILInstruction inst) { Debug.Assert(inst != null); diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index af5f2a406..3aafde82b 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -172,9 +172,8 @@ namespace ICSharpCode.Decompiler.CSharp } var rr = expressionBuilder.resolver.ResolveCast(targetType, ResolveResult); if (rr.IsCompileTimeConstant && !rr.IsError) { - return expressionBuilder.astBuilder.ConvertConstantValue(rr) - .WithILInstruction(this.ILInstructions) - .WithRR(rr); + return expressionBuilder.ConvertConstantValue(rr) + .WithILInstruction(this.ILInstructions); } return Expression.CastTo(expressionBuilder.ConvertType(targetType)) .WithoutILInstruction().WithRR(rr); diff --git a/ILSpy/Properties/app.config.template b/ILSpy/Properties/app.config.template index 76f87c696..e18725fef 100644 --- a/ILSpy/Properties/app.config.template +++ b/ILSpy/Properties/app.config.template @@ -13,7 +13,7 @@ - +