Browse Source

- Altered the InitializerPeepholeTransforms' ArrayInitializer forward-scan to only look at the next instruction: in practice, CSC does not seem to generate code that needs anything more, and there are some questions as to the validity of the looping itself (i.e. what if there is a branch between them?

- Added another test to the InitializerTests, to validate that it handles deeper multi-dimensional arrays (I went 3x3x3 for simplicity)
pull/252/head
Alex Lyman 14 years ago committed by Daniel Grunwald
parent
commit
e484d35fe2
  1. 36
      ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs
  2. 82
      ICSharpCode.Decompiler/Tests/InitializerTests.cs

36
ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

@ -120,25 +120,23 @@ namespace ICSharpCode.Decompiler.ILAst @@ -120,25 +120,23 @@ namespace ICSharpCode.Decompiler.ILAst
bool ForwardScanInitializeArrayRuntimeHelper(List<ILNode> body, int pos, ILVariable array, TypeReference arrayType, int arrayLength, out ILExpression[] values, out int foundPos)
{
for (; pos < body.Count; pos++) {
ILVariable v2;
MethodReference methodRef;
ILExpression methodArg1;
ILExpression methodArg2;
FieldDefinition field;
if (body.ElementAtOrDefault(pos).Match(ILCode.Call, out methodRef, out methodArg1, out methodArg2) &&
methodRef.DeclaringType.FullName == "System.Runtime.CompilerServices.RuntimeHelpers" &&
methodRef.Name == "InitializeArray" &&
methodArg1.Match(ILCode.Ldloc, out v2) &&
array == v2 &&
methodArg2.Match(ILCode.Ldtoken, out field) &&
field != null && field.InitialValue != null) {
ILExpression[] newArr = new ILExpression[arrayLength];
if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()), field.InitialValue, newArr)) {
values = newArr;
foundPos = pos;
return true;
}
ILVariable v2;
MethodReference methodRef;
ILExpression methodArg1;
ILExpression methodArg2;
FieldDefinition field;
if (body.ElementAtOrDefault(pos).Match(ILCode.Call, out methodRef, out methodArg1, out methodArg2) &&
methodRef.DeclaringType.FullName == "System.Runtime.CompilerServices.RuntimeHelpers" &&
methodRef.Name == "InitializeArray" &&
methodArg1.Match(ILCode.Ldloc, out v2) &&
array == v2 &&
methodArg2.Match(ILCode.Ldtoken, out field) &&
field != null && field.InitialValue != null) {
ILExpression[] newArr = new ILExpression[arrayLength];
if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()), field.InitialValue, newArr)) {
values = newArr;
foundPos = pos;
return true;
}
}
values = null;

82
ICSharpCode.Decompiler/Tests/InitializerTests.cs

@ -709,4 +709,86 @@ public class InitializerTests @@ -709,4 +709,86 @@ public class InitializerTests
}
};
}
public void ArrayOfArrayOfArrayInit()
{
int[][,,] array = new int[][,,]
{
new int[, , ]
{
{
{
1,
2,
3
},
{
4,
5,
6
},
{
7,
8,
9
}
},
{
{
11,
12,
13
},
{
14,
15,
16
},
{
17,
18,
19
}
}
},
new int[, , ]
{
{
{
21,
22,
23
},
{
24,
25,
26
},
{
27,
28,
29
}
},
{
{
31,
32,
33
},
{
34,
35,
36
},
{
37,
38,
39
}
}
}
};
}
}

Loading…
Cancel
Save