Browse Source

Negation of operators on nullable values is not allowed for correct decompilation

pull/205/head
Pent Ploompuu 15 years ago
parent
commit
cb174caab3
  1. 2
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 5
      ICSharpCode.Decompiler/ILAst/ILCodes.cs
  3. 9
      ICSharpCode.Decompiler/ILAst/NullableOperators.cs
  4. 1
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

2
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -747,6 +747,8 @@ namespace ICSharpCode.Decompiler.Ast
} }
case ILCode.InitializedObject: case ILCode.InitializedObject:
return new InitializedObjectExpression(); return new InitializedObjectExpression();
case ILCode.Wrap:
return new ParenthesizedExpression(arg1);
case ILCode.AddressOf: case ILCode.AddressOf:
return MakeRef(arg1); return MakeRef(arg1);
default: default:

5
ICSharpCode.Decompiler/ILAst/ILCodes.cs

@ -258,6 +258,11 @@ namespace ICSharpCode.Decompiler.ILAst
LogicOr, LogicOr,
NullCoalescing, NullCoalescing,
InitArray, // Array Initializer InitArray, // Array Initializer
/// <summary>
/// Defines a barrier between the parent opcode and argument opcode that prevents combining them
/// </summary>
Wrap,
// new Class { Prop = 1, Collection = { { 2, 3 }, {4, 5} }} // new Class { Prop = 1, Collection = { { 2, 3 }, {4, 5} }}
// is represented as: // is represented as:

9
ICSharpCode.Decompiler/ILAst/NullableOperators.cs

@ -325,10 +325,11 @@ namespace ICSharpCode.Decompiler.ILAst
var pm = new PatternMatcher(); var pm = new PatternMatcher();
if (!pm.Match(ps[i], expr)) continue; if (!pm.Match(ps[i], expr)) continue;
var n = pm.BuildNew(OperatorVariableAB, expr); var n = pm.BuildNew(OperatorVariableAB, expr);
expr.Code = n.Code; expr.Code = ILCode.Wrap;
expr.Operand = n.Operand; expr.Operand = null;
expr.Arguments = n.Arguments; expr.Arguments.Clear();
expr.ILRanges = n.ILRanges; expr.Arguments.Add(n);
expr.ILRanges.Clear();
expr.InferredType = n.InferredType; expr.InferredType = n.InferredType;
return true; return true;
} }

1
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -749,6 +749,7 @@ namespace ICSharpCode.Decompiler.ILAst
#endregion #endregion
case ILCode.Pop: case ILCode.Pop:
return null; return null;
case ILCode.Wrap:
case ILCode.Dup: case ILCode.Dup:
return InferTypeForExpression(expr.Arguments.Single(), expectedType); return InferTypeForExpression(expr.Arguments.Single(), expectedType);
default: default:

Loading…
Cancel
Save