Browse Source

fix bugs in InitializerTests

pull/728/head
Siegfried Pammer 10 years ago
parent
commit
8a205cd7e2
  1. 37
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 17
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 2
      ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs

37
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -110,40 +110,47 @@ namespace ICSharpCode.Decompiler.CSharp @@ -110,40 +110,47 @@ namespace ICSharpCode.Decompiler.CSharp
if (method != null) {
if (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn)
return true;
if (settings.AnonymousMethods && method.HasGeneratedName() && method.IsCompilerGenerated())
return true;
// if (settings.AnonymousMethods && method.HasGeneratedName() && method.IsCompilerGenerated())
// return true;
}
TypeDefinition type = member as TypeDefinition;
if (type != null) {
if (type.DeclaringType != null) {
if (settings.AnonymousMethods && IsClosureType(type))
return true;
// if (settings.AnonymousMethods && IsClosureType(type))
// return true;
// if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type))
// return true;
// if (settings.AsyncAwait && AsyncDecompiler.IsCompilerGeneratedStateMachine(type))
// return true;
} else if (type.IsCompilerGenerated()) {
if (type.Name.StartsWith("<PrivateImplementationDetails>", StringComparison.Ordinal))
return true;
if (type.IsAnonymousType())
return true;
// if (type.Name.StartsWith("<PrivateImplementationDetails>", StringComparison.Ordinal))
// return true;
// if (type.IsAnonymousType())
// return true;
}
}
FieldDefinition field = member as FieldDefinition;
if (field != null) {
if (field.IsCompilerGenerated()) {
if (settings.AnonymousMethods && IsAnonymousMethodCacheField(field))
return true;
if (settings.AutomaticProperties && IsAutomaticPropertyBackingField(field))
return true;
if (settings.SwitchStatementOnString && IsSwitchOnStringCache(field))
return true;
// if (settings.AnonymousMethods && IsAnonymousMethodCacheField(field))
// return true;
// if (settings.AutomaticProperties && IsAutomaticPropertyBackingField(field))
// return true;
// if (settings.SwitchStatementOnString && IsSwitchOnStringCache(field))
// return true;
}
// event-fields are not [CompilerGenerated]
if (settings.AutomaticEvents && field.DeclaringType.Events.Any(ev => ev.Name == field.Name))
// if (settings.AutomaticEvents && field.DeclaringType.Events.Any(ev => ev.Name == field.Name))
// return true;
// HACK : only hide fields starting with '__StaticArrayInit'
if (field.DeclaringType.Name.StartsWith("<PrivateImplementationDetails>", StringComparison.Ordinal)) {
if (field.Name.StartsWith("__StaticArrayInit", StringComparison.Ordinal))
return true;
if (field.FieldType.Name.StartsWith("__StaticArrayInit", StringComparison.Ordinal))
return true;
}
}
return false;

17
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -616,12 +616,19 @@ namespace ICSharpCode.Decompiler.CSharp @@ -616,12 +616,19 @@ namespace ICSharpCode.Decompiler.CSharp
memoryType = ((ByReferenceType)pointerType).ElementType;
else
return false;
ITypeDefinition memoryTypeDef = memoryType.GetDefinition();
ITypeDefinition accessTypeDef = accessType.GetDefinition();
if (memoryType.Kind == TypeKind.Enum && memoryTypeDef != null) {
memoryType = memoryTypeDef.EnumUnderlyingType;
}
if (accessType.Kind == TypeKind.Enum && accessTypeDef != null) {
accessType = accessTypeDef.EnumUnderlyingType;
}
if (memoryType.Equals(accessType))
return true;
// If the types are not equal, the access still might produce equal results:
if (memoryType.IsReferenceType == true && accessType.IsReferenceType == true)
return true;
ITypeDefinition memoryTypeDef = memoryType.GetDefinition();
if (memoryTypeDef != null) {
switch (memoryTypeDef.KnownTypeCode) {
case KnownTypeCode.Byte:
@ -694,10 +701,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -694,10 +701,12 @@ namespace ICSharpCode.Decompiler.CSharp
{
TranslatedExpression arrayExpr = Translate(inst.Array);
var arrayType = arrayExpr.Type as ArrayType;
// TODO: what if arrayExpr is not an array type?
// TODO: what if the type of the ldelema instruction does not match the array type?
if (arrayType == null) {
arrayType = new ArrayType(compilation, inst.Type, inst.Indices.Count);
arrayExpr = arrayExpr.ConvertTo(arrayType, this);
}
TranslatedExpression expr = new IndexerExpression(arrayExpr, inst.Indices.Select(i => Translate(i).Expression))
.WithILInstruction(inst).WithRR(new ResolveResult(arrayType != null ? arrayType.ElementType : SpecialType.UnknownType));
.WithILInstruction(inst).WithRR(new ResolveResult(arrayType.ElementType));
return new DirectionExpression(FieldDirection.Ref, expr)
.WithoutILInstruction().WithRR(new ResolveResult(new ByReferenceType(expr.Type)));
}

2
ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
string ReplaceInvalid(string s)
{
return string.Concat(s.Select(ch => IsValid(ch) ? ch.ToString() : string.Format("_{0:0000X}", (int)ch)));
return string.Concat(s.Select(ch => IsValid(ch) ? ch.ToString() : string.Format("_{0:X4}", (int)ch)));
}
public void Run(AstNode rootNode, TransformContext context)

Loading…
Cancel
Save