Browse Source

Fixed ILAstOptimizer.CanBeExpressionStatement to include more types of assignments.

Fixed TypeAnalysis.IsEnum so that arrays of enums are not considered to be enums.
pull/252/head
Daniel Grunwald 15 years ago
parent
commit
6c94092dc5
  1. 15
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  2. 4
      ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs
  3. 19
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

15
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -742,9 +742,24 @@ namespace ICSharpCode.Decompiler.ILAst @@ -742,9 +742,24 @@ namespace ICSharpCode.Decompiler.ILAst
// property getters can't be expression statements, but all other method calls can be
MethodReference mr = (MethodReference)expr.Operand;
return !mr.Name.StartsWith("get_", StringComparison.Ordinal);
case ILCode.CallSetter:
case ILCode.CallvirtSetter:
case ILCode.Newobj:
case ILCode.Newarr:
case ILCode.Stloc:
case ILCode.Stobj:
case ILCode.Stsfld:
case ILCode.Stfld:
case ILCode.Stind_Ref:
case ILCode.Stelem_Any:
case ILCode.Stelem_I:
case ILCode.Stelem_I1:
case ILCode.Stelem_I2:
case ILCode.Stelem_I4:
case ILCode.Stelem_I8:
case ILCode.Stelem_R4:
case ILCode.Stelem_R8:
case ILCode.Stelem_Ref:
return true;
default:
return false;

4
ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.ILAst
#region Array Initializers
bool TransformArrayInitializers(List<ILNode> body, ILExpression expr, int pos)
{
ILVariable v, v2, v3;
ILVariable v, v3;
ILExpression newarrExpr;
TypeReference elementType;
ILExpression lengthExpr;
@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.ILAst
bool TransformMultidimensionalArrayInitializers(List<ILNode> body, ILExpression expr, int pos)
{
ILVariable v, v2, v3;
ILVariable v;
ILExpression newarrExpr;
MethodReference ctor;
List<ILExpression> ctorArgs;

19
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -957,7 +957,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -957,7 +957,7 @@ namespace ICSharpCode.Decompiler.ILAst
{
if (type == null)
return 0;
if (type.IsValueType) {
if (type.IsValueType && !IsArrayPointerOrReference(type)) {
// value type might be an enum
TypeDefinition typeDef = type.Resolve() as TypeDefinition;
if (typeDef != null && typeDef.IsEnum) {
@ -1005,7 +1005,9 @@ namespace ICSharpCode.Decompiler.ILAst @@ -1005,7 +1005,9 @@ namespace ICSharpCode.Decompiler.ILAst
public static bool IsEnum(TypeReference type)
{
if (type == null)
// Arrays/Pointers/ByReference resolve to their element type, but we don't want to consider those to be enums
// However, GenericInstanceTypes, ModOpts etc. should be considered enums.
if (type == null || IsArrayPointerOrReference(type))
return false;
// unfortunately we cannot rely on type.IsValueType here - it's not set when the instruction operand is a typeref (as opposed to a typespec)
TypeDefinition typeDef = type.Resolve() as TypeDefinition;
@ -1014,7 +1016,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -1014,7 +1016,7 @@ namespace ICSharpCode.Decompiler.ILAst
static bool? IsSigned(TypeReference type)
{
if (type == null)
if (type == null || IsArrayPointerOrReference(type))
return null;
// unfortunately we cannot rely on type.IsValueType here - it's not set when the instruction operand is a typeref (as opposed to a typespec)
TypeDefinition typeDef = type.Resolve() as TypeDefinition;
@ -1041,6 +1043,17 @@ namespace ICSharpCode.Decompiler.ILAst @@ -1041,6 +1043,17 @@ namespace ICSharpCode.Decompiler.ILAst
}
}
static bool IsArrayPointerOrReference(TypeReference type)
{
TypeSpecification typeSpec = type as TypeSpecification;
while (typeSpec != null) {
if (typeSpec is ArrayType || typeSpec is PointerType || typeSpec is ByReferenceType)
return true;
typeSpec = typeSpec.ElementType as TypeSpecification;
}
return false;
}
public static TypeCode GetTypeCode(TypeReference type)
{
if (type == null)

Loading…
Cancel
Save