Browse Source

Fix bug in Clone() impl for collection slots.

pull/728/head
Daniel Grunwald 9 years ago
parent
commit
8edfe57b85
  1. 6
      ICSharpCode.Decompiler/IL/Instructions.cs
  2. 2
      ICSharpCode.Decompiler/IL/Instructions.tt
  3. 5
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

6
ICSharpCode.Decompiler/IL/Instructions.cs

@ -414,7 +414,7 @@ namespace ICSharpCode.Decompiler.IL @@ -414,7 +414,7 @@ namespace ICSharpCode.Decompiler.IL
public sealed override ILInstruction Clone()
{
var clone = (CallInstruction)ShallowClone();
clone.Arguments = new InstructionCollection<ILInstruction>(this, 0);
clone.Arguments = new InstructionCollection<ILInstruction>(clone, 0);
clone.Arguments.AddRange(this.Arguments.Select(arg => arg.Clone()));
return clone;
}
@ -2631,7 +2631,7 @@ namespace ICSharpCode.Decompiler.IL @@ -2631,7 +2631,7 @@ namespace ICSharpCode.Decompiler.IL
public sealed override ILInstruction Clone()
{
var clone = (NewArr)ShallowClone();
clone.Indices = new InstructionCollection<ILInstruction>(this, 0);
clone.Indices = new InstructionCollection<ILInstruction>(clone, 0);
clone.Indices.AddRange(this.Indices.Select(arg => arg.Clone()));
return clone;
}
@ -2896,7 +2896,7 @@ namespace ICSharpCode.Decompiler.IL @@ -2896,7 +2896,7 @@ namespace ICSharpCode.Decompiler.IL
{
var clone = (LdElema)ShallowClone();
clone.Array = this.array.Clone();
clone.Indices = new InstructionCollection<ILInstruction>(this, 1);
clone.Indices = new InstructionCollection<ILInstruction>(clone, 1);
clone.Indices.AddRange(this.Indices.Select(arg => arg.Clone()));
return clone;
}

2
ICSharpCode.Decompiler/IL/Instructions.tt

@ -737,7 +737,7 @@ namespace ICSharpCode.Decompiler.IL @@ -737,7 +737,7 @@ namespace ICSharpCode.Decompiler.IL
b.AppendLine("\tvar clone = (" + opCode.Name + ")ShallowClone();");
for (int i = 0; i < children.Length; i++) {
if (children[i].IsCollection) {
b.AppendLine("\tclone." + children[i].PropertyName + " = new InstructionCollection<ILInstruction>(this, " + i + ");");
b.AppendLine("\tclone." + children[i].PropertyName + " = new InstructionCollection<ILInstruction>(clone, " + i + ");");
b.AppendLine("\tclone." + children[i].PropertyName + ".AddRange(this." + children[i].PropertyName + ".Select(arg => arg.Clone()));");
} else
b.AppendLine("\tclone." + children[i].PropertyName + " = this." + children[i].Name + ".Clone();");

5
ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

@ -522,6 +522,11 @@ namespace ICSharpCode.Decompiler.IL @@ -522,6 +522,11 @@ namespace ICSharpCode.Decompiler.IL
/// <summary>
/// Creates a deep clone of the ILInstruction.
/// </summary>
/// <remarks>
/// It is valid to clone nodes with stale positions (see remarks on <c>Parent</c>);
/// the result of such a clone will not contain any stale positions (nodes at
/// multiple positions will be cloned once per position).
/// </remarks>
public abstract ILInstruction Clone();
/// <summary>

Loading…
Cancel
Save