Browse Source

Cleanup and fix ILRanges in DelegateConstruction.

pull/1440/head
Siegfried Pammer 7 years ago committed by Daniel Grunwald
parent
commit
84cf4ea6a1
  1. 14
      ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

14
ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

@ -316,7 +316,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
field = (IField)field.MemberDefinition; field = (IField)field.MemberDefinition;
ILInstruction value; ILInstruction value;
if (initValues.TryGetValue(field, out DisplayClassVariable info)) { if (initValues.TryGetValue(field, out DisplayClassVariable info)) {
inst.ReplaceWith(new StLoc(info.variable, inst.Value)); inst.ReplaceWith(new StLoc(info.variable, inst.Value) { ILRange = inst.ILRange });
} else { } else {
if (inst.Value.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter && currentFunction == v.Function) { if (inst.Value.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter && currentFunction == v.Function) {
// special case for parameters: remove copies of parameter values. // special case for parameters: remove copies of parameter values.
@ -327,7 +327,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return; return;
v = currentFunction.RegisterVariable(VariableKind.Local, field.Type, field.Name); v = currentFunction.RegisterVariable(VariableKind.Local, field.Type, field.Name);
v.CaptureScope = captureScope; v.CaptureScope = captureScope;
inst.ReplaceWith(new StLoc(v, inst.Value)); inst.ReplaceWith(new StLoc(v, inst.Value) { ILRange = inst.ILRange });
value = new LdLoc(v); value = new LdLoc(v);
} }
initValues.Add(field, new DisplayClassVariable { value = value, variable = v }); initValues.Add(field, new DisplayClassVariable { value = value, variable = v });
@ -341,7 +341,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return; return;
if (!initValues.TryGetValue((IField)field.MemberDefinition, out DisplayClassVariable info)) if (!initValues.TryGetValue((IField)field.MemberDefinition, out DisplayClassVariable info))
return; return;
inst.ReplaceWith(info.value.Clone()); var replacement = info.value.Clone();
replacement.ILRange = inst.ILRange;
inst.ReplaceWith(replacement);
} }
protected internal override void VisitLdFlda(LdFlda inst) protected internal override void VisitLdFlda(LdFlda inst)
@ -362,11 +364,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return; return;
var v = currentFunction.RegisterVariable(VariableKind.Local, field.Type, field.Name); var v = currentFunction.RegisterVariable(VariableKind.Local, field.Type, field.Name);
v.CaptureScope = captureScope; v.CaptureScope = captureScope;
inst.ReplaceWith(new LdLoca(v)); inst.ReplaceWith(new LdLoca(v) { ILRange = inst.ILRange });
var value = new LdLoc(v); var value = new LdLoc(v);
initValues.Add(field, new DisplayClassVariable { value = value, variable = v }); initValues.Add(field, new DisplayClassVariable { value = value, variable = v });
} else if (info.value is LdLoc l) { } else if (info.value is LdLoc l) {
inst.ReplaceWith(new LdLoca(l.Variable)); inst.ReplaceWith(new LdLoca(l.Variable) { ILRange = inst.ILRange });
} else { } else {
Debug.Fail("LdFlda pattern not supported!"); Debug.Fail("LdFlda pattern not supported!");
} }
@ -376,7 +378,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
base.VisitNumericCompoundAssign(inst); base.VisitNumericCompoundAssign(inst);
if (inst.Target.MatchLdLoc(out var v)) { if (inst.Target.MatchLdLoc(out var v)) {
inst.ReplaceWith(new StLoc(v, new BinaryNumericInstruction(inst.Operator, inst.Target, inst.Value, inst.CheckForOverflow, inst.Sign))); inst.ReplaceWith(new StLoc(v, new BinaryNumericInstruction(inst.Operator, inst.Target, inst.Value, inst.CheckForOverflow, inst.Sign) { ILRange = inst.ILRange }));
} }
} }
} }

Loading…
Cancel
Save