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 @@ -1987,7 +1987,7 @@ namespace ICSharpCode.Decompiler.CSharp
indexVariables.Add(indexStore.Variable, indexStore.Value);
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 (currentPath == null) {
currentPath = info.Path;

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

@ -175,7 +175,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -175,7 +175,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
possibleIndexVariables.Add(stloc.Variable, (stloc.ChildIndex, stloc.Value));
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)
return false;
// Treat last element separately:
@ -240,7 +240,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -240,7 +240,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
public override string ToString() => $"[{Member}, {Indices}]";
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>();
ILVariable target = null;
@ -259,6 +259,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -259,6 +259,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var property = method.AccessorOwner as IProperty;
var isGetter = method.Equals(property?.Getter);
var indices = call.Arguments.Skip(1).Take(call.Arguments.Count - (isGetter ? 1 : 2)).ToArray();
if (indices.Length > 0 && !allowDictionaryInitializer) goto default;
if (possibleIndexVariables != null) {
// Mark all index variables as used
foreach (var index in indices.OfType<IInstructionWithVariableOperand>()) {

Loading…
Cancel
Save