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
if (method != null) { if (method != null) {
if (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn) if (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn)
return true; return true;
if (settings.AnonymousMethods && method.HasGeneratedName() && method.IsCompilerGenerated()) // if (settings.AnonymousMethods && method.HasGeneratedName() && method.IsCompilerGenerated())
return true; // return true;
} }
TypeDefinition type = member as TypeDefinition; TypeDefinition type = member as TypeDefinition;
if (type != null) { if (type != null) {
if (type.DeclaringType != null) { if (type.DeclaringType != null) {
if (settings.AnonymousMethods && IsClosureType(type)) // if (settings.AnonymousMethods && IsClosureType(type))
return true; // return true;
// if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type)) // if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type))
// return true; // return true;
// if (settings.AsyncAwait && AsyncDecompiler.IsCompilerGeneratedStateMachine(type)) // if (settings.AsyncAwait && AsyncDecompiler.IsCompilerGeneratedStateMachine(type))
// return true; // return true;
} else if (type.IsCompilerGenerated()) { } else if (type.IsCompilerGenerated()) {
if (type.Name.StartsWith("<PrivateImplementationDetails>", StringComparison.Ordinal)) // if (type.Name.StartsWith("<PrivateImplementationDetails>", StringComparison.Ordinal))
return true; // return true;
if (type.IsAnonymousType()) // if (type.IsAnonymousType())
return true; // return true;
} }
} }
FieldDefinition field = member as FieldDefinition; FieldDefinition field = member as FieldDefinition;
if (field != null) { if (field != null) {
if (field.IsCompilerGenerated()) { if (field.IsCompilerGenerated()) {
if (settings.AnonymousMethods && IsAnonymousMethodCacheField(field)) // if (settings.AnonymousMethods && IsAnonymousMethodCacheField(field))
return true; // return true;
if (settings.AutomaticProperties && IsAutomaticPropertyBackingField(field)) // 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))
// 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; return true;
if (settings.SwitchStatementOnString && IsSwitchOnStringCache(field)) if (field.FieldType.Name.StartsWith("__StaticArrayInit", StringComparison.Ordinal))
return true; return true;
} }
// event-fields are not [CompilerGenerated]
if (settings.AutomaticEvents && field.DeclaringType.Events.Any(ev => ev.Name == field.Name))
return true;
} }
return false; return false;

17
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -616,12 +616,19 @@ namespace ICSharpCode.Decompiler.CSharp
memoryType = ((ByReferenceType)pointerType).ElementType; memoryType = ((ByReferenceType)pointerType).ElementType;
else else
return false; 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)) if (memoryType.Equals(accessType))
return true; return true;
// If the types are not equal, the access still might produce equal results: // If the types are not equal, the access still might produce equal results:
if (memoryType.IsReferenceType == true && accessType.IsReferenceType == true) if (memoryType.IsReferenceType == true && accessType.IsReferenceType == true)
return true; return true;
ITypeDefinition memoryTypeDef = memoryType.GetDefinition();
if (memoryTypeDef != null) { if (memoryTypeDef != null) {
switch (memoryTypeDef.KnownTypeCode) { switch (memoryTypeDef.KnownTypeCode) {
case KnownTypeCode.Byte: case KnownTypeCode.Byte:
@ -694,10 +701,12 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
TranslatedExpression arrayExpr = Translate(inst.Array); TranslatedExpression arrayExpr = Translate(inst.Array);
var arrayType = arrayExpr.Type as ArrayType; var arrayType = arrayExpr.Type as ArrayType;
// TODO: what if arrayExpr is not an array type? if (arrayType == null) {
// TODO: what if the type of the ldelema instruction does not match the array type? 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)) 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) return new DirectionExpression(FieldDirection.Ref, expr)
.WithoutILInstruction().WithRR(new ResolveResult(new ByReferenceType(expr.Type))); .WithoutILInstruction().WithRR(new ResolveResult(new ByReferenceType(expr.Type)));
} }

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

@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
string ReplaceInvalid(string s) 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) public void Run(AstNode rootNode, TransformContext context)

Loading…
Cancel
Save