Browse Source

Fix #1155: DictionaryInitializers setting not working

pull/1167/head
Siegfried Pammer 7 years ago
parent
commit
b9f14905b2
  1. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 5
      ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1987,7 +1987,7 @@ namespace ICSharpCode.Decompiler.CSharp
indexVariables.Add(indexStore.Variable, indexStore.Value); indexVariables.Add(indexStore.Variable, indexStore.Value);
continue; continue;
} }
var info = IL.Transforms.AccessPathElement.GetAccessPath(inst, initObjRR.Type); var info = IL.Transforms.AccessPathElement.GetAccessPath(inst, initObjRR.Type, allowDictionaryInitializer: settings.DictionaryInitializers);
if (info.Kind == IL.Transforms.AccessPathKind.Invalid) continue; if (info.Kind == IL.Transforms.AccessPathKind.Invalid) continue;
if (currentPath == null) { if (currentPath == null) {
currentPath = info.Path; currentPath = info.Path;

5
ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

@ -175,7 +175,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
possibleIndexVariables.Add(stloc.Variable, (stloc.ChildIndex, stloc.Value)); possibleIndexVariables.Add(stloc.Variable, (stloc.ChildIndex, stloc.Value));
return true; return true;
} }
(var kind, var newPath, var values, var targetVariable) = AccessPathElement.GetAccessPath(instructions[pos], rootType, possibleIndexVariables); (var kind, var newPath, var values, var targetVariable) = AccessPathElement.GetAccessPath(instructions[pos], rootType, possibleIndexVariables, allowDictionaryInitializer: context.Settings.DictionaryInitializers);
if (kind == AccessPathKind.Invalid || target != targetVariable) if (kind == AccessPathKind.Invalid || target != targetVariable)
return false; return false;
// Treat last element separately: // Treat last element separately:
@ -240,7 +240,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
public override string ToString() => $"[{Member}, {Indices}]"; public override string ToString() => $"[{Member}, {Indices}]";
public static (AccessPathKind Kind, List<AccessPathElement> Path, List<ILInstruction> Values, ILVariable Target) GetAccessPath( public static (AccessPathKind Kind, List<AccessPathElement> Path, List<ILInstruction> Values, ILVariable Target) GetAccessPath(
ILInstruction instruction, IType rootType, Dictionary<ILVariable, (int Index, ILInstruction Value)> possibleIndexVariables = null) ILInstruction instruction, IType rootType, Dictionary<ILVariable, (int Index, ILInstruction Value)> possibleIndexVariables = null, bool allowDictionaryInitializer = false)
{ {
List<AccessPathElement> path = new List<AccessPathElement>(); List<AccessPathElement> path = new List<AccessPathElement>();
ILVariable target = null; ILVariable target = null;
@ -259,6 +259,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var property = method.AccessorOwner as IProperty; var property = method.AccessorOwner as IProperty;
var isGetter = method.Equals(property?.Getter); var isGetter = method.Equals(property?.Getter);
var indices = call.Arguments.Skip(1).Take(call.Arguments.Count - (isGetter ? 1 : 2)).ToArray(); var indices = call.Arguments.Skip(1).Take(call.Arguments.Count - (isGetter ? 1 : 2)).ToArray();
if (indices.Length > 0 && !allowDictionaryInitializer) goto default;
if (possibleIndexVariables != null) { if (possibleIndexVariables != null) {
// Mark all index variables as used // Mark all index variables as used
foreach (var index in indices.OfType<IInstructionWithVariableOperand>()) { foreach (var index in indices.OfType<IInstructionWithVariableOperand>()) {

Loading…
Cancel
Save