|
|
@ -41,8 +41,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms |
|
|
|
for (int i = block.Instructions.Count - 1; i >= 0; i--) { |
|
|
|
for (int i = block.Instructions.Count - 1; i >= 0; i--) { |
|
|
|
context.CancellationToken.ThrowIfCancellationRequested(); |
|
|
|
context.CancellationToken.ThrowIfCancellationRequested(); |
|
|
|
foreach (var call in block.Instructions[i].Descendants.OfType<NewObj>()) { |
|
|
|
foreach (var call in block.Instructions[i].Descendants.OfType<NewObj>()) { |
|
|
|
ILInstruction target; |
|
|
|
ILFunction f = TransformDelegateConstruction(call, out ILInstruction target); |
|
|
|
ILFunction f = TransformDelegateConstruction(call, out target); |
|
|
|
|
|
|
|
if (f != null) { |
|
|
|
if (f != null) { |
|
|
|
call.Arguments[0].ReplaceWith(new Nop()); |
|
|
|
call.Arguments[0].ReplaceWith(new Nop()); |
|
|
|
call.Arguments[1].ReplaceWith(f); |
|
|
|
call.Arguments[1].ReplaceWith(f); |
|
|
@ -50,10 +49,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms |
|
|
|
targetsToReplace.Add((IInstructionWithVariableOperand)target); |
|
|
|
targetsToReplace.Add((IInstructionWithVariableOperand)target); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (block.Instructions[i].MatchStLoc(out ILVariable targetVariable, out ILInstruction value)) { |
|
|
|
ILVariable targetVariable; |
|
|
|
|
|
|
|
ILInstruction value; |
|
|
|
|
|
|
|
if (block.Instructions[i].MatchStLoc(out targetVariable, out value)) { |
|
|
|
|
|
|
|
var newObj = value as NewObj; |
|
|
|
var newObj = value as NewObj; |
|
|
|
// TODO : it is probably not a good idea to remove *all* display-classes
|
|
|
|
// TODO : it is probably not a good idea to remove *all* display-classes
|
|
|
|
// is there a way to minimize the false-positives?
|
|
|
|
// is there a way to minimize the false-positives?
|
|
|
@ -261,14 +257,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms |
|
|
|
protected internal override void VisitStObj(StObj inst) |
|
|
|
protected internal override void VisitStObj(StObj inst) |
|
|
|
{ |
|
|
|
{ |
|
|
|
base.VisitStObj(inst); |
|
|
|
base.VisitStObj(inst); |
|
|
|
ILInstruction target; |
|
|
|
if (!inst.Target.MatchLdFlda(out ILInstruction target, out IField field) || !MatchesTargetOrCopyLoad(target)) |
|
|
|
IField field; |
|
|
|
|
|
|
|
if (!inst.Target.MatchLdFlda(out target, out field) || !MatchesTargetOrCopyLoad(target)) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
field = (IField)field.MemberDefinition; |
|
|
|
field = (IField)field.MemberDefinition; |
|
|
|
DisplayClassVariable info; |
|
|
|
|
|
|
|
ILInstruction value; |
|
|
|
ILInstruction value; |
|
|
|
if (initValues.TryGetValue(field, out info)) { |
|
|
|
if (initValues.TryGetValue(field, out DisplayClassVariable info)) { |
|
|
|
inst.ReplaceWith(new StLoc(info.variable, inst.Value)); |
|
|
|
inst.ReplaceWith(new StLoc(info.variable, inst.Value)); |
|
|
|
} 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) { |
|
|
@ -288,12 +281,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms |
|
|
|
protected internal override void VisitLdObj(LdObj inst) |
|
|
|
protected internal override void VisitLdObj(LdObj inst) |
|
|
|
{ |
|
|
|
{ |
|
|
|
base.VisitLdObj(inst); |
|
|
|
base.VisitLdObj(inst); |
|
|
|
ILInstruction target; |
|
|
|
if (!inst.Target.MatchLdFlda(out ILInstruction target, out IField field)) |
|
|
|
IField field; |
|
|
|
|
|
|
|
if (!inst.Target.MatchLdFlda(out target, out field)) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
DisplayClassVariable info; |
|
|
|
if (!initValues.TryGetValue((IField)field.MemberDefinition, out DisplayClassVariable info)) |
|
|
|
if (!initValues.TryGetValue((IField)field.MemberDefinition, out info)) |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
inst.ReplaceWith(info.value.Clone()); |
|
|
|
inst.ReplaceWith(info.value.Clone()); |
|
|
|
} |
|
|
|
} |
|
|
@ -306,8 +296,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms |
|
|
|
if (!MatchesTargetOrCopyLoad(inst.Target)) |
|
|
|
if (!MatchesTargetOrCopyLoad(inst.Target)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
var field = (IField)inst.Field.MemberDefinition; |
|
|
|
var field = (IField)inst.Field.MemberDefinition; |
|
|
|
DisplayClassVariable info; |
|
|
|
if (!initValues.TryGetValue(field, out DisplayClassVariable info)) { |
|
|
|
if (!initValues.TryGetValue(field, out info)) { |
|
|
|
|
|
|
|
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)); |
|
|
|