Browse Source

Add ILVariable.IsDead property

pull/2005/head
Siegfried Pammer 5 years ago
parent
commit
83e8049114
  1. 11
      ICSharpCode.Decompiler/IL/ILVariable.cs
  2. 3
      ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs

11
ICSharpCode.Decompiler/IL/ILVariable.cs

@ -337,6 +337,17 @@ namespace ICSharpCode.Decompiler.IL
} }
} }
/// <summary>
/// Gets whether the variable is dead - unused.
/// </summary>
public bool IsDead {
get {
return StoreCount == (HasInitialValue ? 1 : 0)
&& LoadCount == 0
&& AddressCount == 0;
}
}
/// <summary> /// <summary>
/// The field which was converted to a local variable. /// The field which was converted to a local variable.
/// Set when the variable is from a 'yield return' or 'async' state machine. /// Set when the variable is from a 'yield return' or 'async' state machine.

3
ICSharpCode.Decompiler/IL/Instructions/ILVariableCollection.cs

@ -102,8 +102,7 @@ namespace ICSharpCode.Decompiler.IL
{ {
for (int i = 0; i < list.Count;) { for (int i = 0; i < list.Count;) {
var v = list[i]; var v = list[i];
int deadStoreCount = v.HasInitialValue ? 1 : 0; if (v.IsDead && v.Kind != VariableKind.DisplayClassLocal) {
if (v.StoreCount == deadStoreCount && v.LoadCount == 0 && v.AddressCount == 0 && v.Kind != VariableKind.DisplayClassLocal) {
RemoveAt(i); RemoveAt(i);
} else { } else {
i++; i++;

Loading…
Cancel
Save