From f05c1bb4664f5a4b6becd654d22adfe82218062c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 24 Feb 2019 10:29:37 +0100 Subject: [PATCH] Fix build break; only escape _ if it is a type name. Add basic Discards tests. --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 6 + .../TestCases/Pretty/Discards.cs | 42 ++++ .../TestCases/Pretty/Discards.opt.roslyn.il | 178 ++++++++++++++++ .../TestCases/Pretty/Discards.roslyn.il | 190 ++++++++++++++++++ .../OutputVisitor/CSharpOutputVisitor.cs | 6 +- .../CSharp/Syntax/TypeSystemAstBuilder.cs | 40 ++-- 7 files changed, 445 insertions(+), 18 deletions(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index b899c371b..8722e4194 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -68,6 +68,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index c9b708841..69071472e 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -420,6 +420,12 @@ namespace ICSharpCode.Decompiler.Tests RunForLibrary(cscOptions: cscOptions); } + [Test] + public void Discards([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) + { + RunForLibrary(cscOptions: cscOptions); + } + void RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) { Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.cs new file mode 100644 index 000000000..a9997fd85 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.cs @@ -0,0 +1,42 @@ +using System; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + internal class Discards + { + public class @_ + { + + } + + public void GetOut(out int value) + { + value = 0; + } + + public void MakeValue(Func func) + { + + } + + public void MakeValue(Func<@_, int> func) + { + + } + + public void SimpleParameter(@_ _) + { + } + + public void ParameterHiddenByLocal(@_ _) + { + GetOut(out int _); + } + + public void DiscardedOutVsLambdaParameter() + { + GetOut(out int _); + MakeValue((@_ _) => 5); + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.opt.roslyn.il new file mode 100644 index 000000000..7813589e2 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.opt.roslyn.il @@ -0,0 +1,178 @@ + + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly Discards +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module Discards.dll +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards + extends [mscorlib]System.Object +{ + .class auto ansi nested public beforefieldinit _ + extends [mscorlib]System.Object + { + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method _::.ctor + + } // end of class _ + + .class auto ansi serializable sealed nested private beforefieldinit '<>c' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c' '<>9' + .field public static class [mscorlib]System.Func`2 '<>9__6_0' + .method private hidebysig specialname rtspecialname static + void .cctor() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::.ctor() + IL_0005: stsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9' + IL_000a: ret + } // end of method '<>c'::.cctor + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method '<>c'::.ctor + + .method assembly hidebysig instance int32 + 'b__6_0'(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_ _) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.5 + IL_0001: ret + } // end of method '<>c'::'b__6_0' + + } // end of class '<>c' + + .method public hidebysig instance void + GetOut([out] int32& 'value') cil managed + { + // Code size 4 (0x4) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldc.i4.0 + IL_0002: stind.i4 + IL_0003: ret + } // end of method Discards::GetOut + + .method public hidebysig instance void + MakeValue(class [mscorlib]System.Func`3 func) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Discards::MakeValue + + .method public hidebysig instance void + MakeValue(class [mscorlib]System.Func`2 func) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Discards::MakeValue + + .method public hidebysig instance void + SimpleParameter(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_ _) cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method Discards::SimpleParameter + + .method public hidebysig instance void + ParameterHiddenByLocal(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_ _) cil managed + { + // Code size 9 (0x9) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldloca.s V_0 + IL_0003: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards::GetOut(int32&) + IL_0008: ret + } // end of method Discards::ParameterHiddenByLocal + + .method public hidebysig instance void + DiscardedOutVsLambdaParameter() cil managed + { + // Code size 46 (0x2e) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldloca.s V_0 + IL_0003: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards::GetOut(int32&) + IL_0008: ldarg.0 + IL_0009: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9__6_0' + IL_000e: dup + IL_000f: brtrue.s IL_0028 + + IL_0011: pop + IL_0012: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9' + IL_0017: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'b__6_0'(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_) + IL_001d: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0022: dup + IL_0023: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9__6_0' + IL_0028: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards::MakeValue(class [mscorlib]System.Func`2) + IL_002d: ret + } // end of method Discards::DiscardedOutVsLambdaParameter + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method Discards::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.roslyn.il new file mode 100644 index 000000000..b0bc0b6f0 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Discards.roslyn.il @@ -0,0 +1,190 @@ + + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly Discards +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module Discards.dll +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards + extends [mscorlib]System.Object +{ + .class auto ansi nested public beforefieldinit _ + extends [mscorlib]System.Object + { + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method _::.ctor + + } // end of class _ + + .class auto ansi serializable sealed nested private beforefieldinit '<>c' + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c' '<>9' + .field public static class [mscorlib]System.Func`2 '<>9__6_0' + .method private hidebysig specialname rtspecialname static + void .cctor() cil managed + { + // Code size 11 (0xb) + .maxstack 8 + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::.ctor() + IL_0005: stsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9' + IL_000a: ret + } // end of method '<>c'::.cctor + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method '<>c'::.ctor + + .method assembly hidebysig instance int32 + 'b__6_0'(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_ _) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.5 + IL_0001: ret + } // end of method '<>c'::'b__6_0' + + } // end of class '<>c' + + .method public hidebysig instance void + GetOut([out] int32& 'value') cil managed + { + // Code size 5 (0x5) + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldc.i4.0 + IL_0003: stind.i4 + IL_0004: ret + } // end of method Discards::GetOut + + .method public hidebysig instance void + MakeValue(class [mscorlib]System.Func`3 func) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Discards::MakeValue + + .method public hidebysig instance void + MakeValue(class [mscorlib]System.Func`2 func) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Discards::MakeValue + + .method public hidebysig instance void + SimpleParameter(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_ _) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method Discards::SimpleParameter + + .method public hidebysig instance void + ParameterHiddenByLocal(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_ _) cil managed + { + // Code size 11 (0xb) + .maxstack 2 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards::GetOut(int32&) + IL_0009: nop + IL_000a: ret + } // end of method Discards::ParameterHiddenByLocal + + .method public hidebysig instance void + DiscardedOutVsLambdaParameter() cil managed + { + // Code size 49 (0x31) + .maxstack 3 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldloca.s V_0 + IL_0004: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards::GetOut(int32&) + IL_0009: nop + IL_000a: ldarg.0 + IL_000b: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9__6_0' + IL_0010: dup + IL_0011: brtrue.s IL_002a + + IL_0013: pop + IL_0014: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9' + IL_0019: ldftn instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'b__6_0'(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/_) + IL_001f: newobj instance void class [mscorlib]System.Func`2::.ctor(object, + native int) + IL_0024: dup + IL_0025: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards/'<>c'::'<>9__6_0' + IL_002a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards::MakeValue(class [mscorlib]System.Func`2) + IL_002f: nop + IL_0030: ret + } // end of method Discards::DiscardedOutVsLambdaParameter + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method Discards::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.Discards + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index 21acadc9a..9992fa33e 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -395,13 +395,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor public static bool IsKeyword(string identifier, AstNode context) { // only 2-10 char lower-case identifiers can be keywords - if (identifier.Length > maxKeywordLength || identifier.Length == 0) { + if (identifier.Length > maxKeywordLength || identifier.Length < 2 || identifier[0] < 'a') { return false; } - if (identifier[0] < 'a') { - // we escape _ as identifier to avoid ambiguities with discard patterns - return identifier == "_"; - } if (unconditionalKeywords.Contains(identifier)) { return true; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index 6c04e4b84..fe4b77844 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -226,12 +226,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax TopLevelTypeName top = fullTypeName.TopLevelTypeName; AstType type; if (string.IsNullOrEmpty(top.Namespace)) { - type = new SimpleType(top.Name); + type = MakeSimpleType(top.Name); } else { - type = new SimpleType(top.Namespace).MemberType(top.Name); + type = MakeMemberType(MakeSimpleType(top.Namespace), top.Name); } for (int i = 0; i < fullTypeName.NestingLevel; i++) { - type = type.MemberType(fullTypeName.GetNestedTypeName(i)); + type = MakeMemberType(type, fullTypeName.GetNestedTypeName(i)); } return type; } @@ -282,7 +282,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } } - return new SimpleType(type.Name); + return MakeSimpleType(type.Name); } AstType ConvertTypeHelper(IType genericType, IReadOnlyList typeArguments) @@ -307,7 +307,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax foreach (var pair in usingScope.UsingAliases) { if (pair.Value is TypeResolveResult) { if (TypeMatches(pair.Value.Type, typeDef, typeArguments)) - return new SimpleType(pair.Key); + return MakeSimpleType(pair.Key); } } } @@ -327,7 +327,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax if (trr != null || (localTypeArguments.Length == 0 && resolver.IsVariableReferenceWithSameType(rr, typeDef.Name, out trr))) { if (!trr.IsError && TypeMatches(trr.Type, typeDef, typeArguments)) { // We can use the short type name - SimpleType shortResult = new SimpleType(typeDef.Name); + SimpleType shortResult = MakeSimpleType(typeDef.Name); AddTypeArguments(shortResult, typeDef.TypeParameters, typeArguments, outerTypeParameterCount, typeDef.TypeParameterCount); return shortResult; } @@ -335,7 +335,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax } if (AlwaysUseShortTypeNames || (typeDef == null && genericType.DeclaringType == null)) { - var shortResult = new SimpleType(genericType.Name); + var shortResult = MakeSimpleType(genericType.Name); AddTypeArguments(shortResult, genericType.TypeParameters, typeArguments, outerTypeParameterCount, genericType.TypeParameterCount); return shortResult; } @@ -395,7 +395,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax Debug.Assert(endIndex <= typeParameters.Count); for (int i = startIndex; i < endIndex; i++) { if (ConvertUnboundTypeArguments && typeArguments[i].Kind == TypeKind.UnboundTypeArgument) { - result.AddChild(new SimpleType(typeParameters[i].Name), Roles.TypeArgument); + result.AddChild(MakeSimpleType(typeParameters[i].Name), Roles.TypeArgument); } else { result.AddChild(ConvertType(typeArguments[i]), Roles.TypeArgument); } @@ -411,7 +411,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax foreach (var pair in usingScope.UsingAliases) { nrr = pair.Value as NamespaceResolveResult; if (nrr != null && nrr.NamespaceName == namespaceName) { - var ns = new SimpleType(pair.Key); + var ns = MakeSimpleType(pair.Key); if (AddResolveResultAnnotations) ns.AddAnnotation(nrr); return ns; @@ -424,7 +424,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax int pos = namespaceName.LastIndexOf('.'); if (pos < 0) { if (IsValidNamespace(namespaceName, out nrr)) { - var ns = new SimpleType(namespaceName); + var ns = MakeSimpleType(namespaceName); if (AddResolveResultAnnotations && nrr != null) ns.AddAnnotation(nrr); return ns; @@ -471,8 +471,22 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax nrr = resolver.ResolveSimpleName(firstNamespacePart, EmptyList.Instance) as NamespaceResolveResult; return nrr != null && !nrr.IsError && nrr.NamespaceName == firstNamespacePart; } + + static SimpleType MakeSimpleType(string name) + { + if (name == "_") + return new SimpleType("@_"); + return new SimpleType(name); + } + + static MemberType MakeMemberType(AstType target, string name) + { + if (name == "_") + return new MemberType(target, "@_"); + return new MemberType(target, name); + } #endregion - + #region Convert Attribute public Attribute ConvertAttribute(IAttribute attribute) { @@ -1334,7 +1348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax if (AddResolveResultAnnotations) { decl.AddAnnotation(new TypeResolveResult(typeDefinition)); } - decl.Name = typeDefinition.Name; + decl.Name = typeDefinition.Name == "_" ? "@_" : typeDefinition.Name; int outerTypeParameterCount = (typeDefinition.DeclaringTypeDefinition == null) ? 0 : typeDefinition.DeclaringTypeDefinition.TypeParameterCount; @@ -1714,7 +1728,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return null; } Constraint c = new Constraint(); - c.TypeParameter = new SimpleType (tp.Name); + c.TypeParameter = MakeSimpleType(tp.Name); if (tp.HasReferenceTypeConstraint) { c.BaseTypes.Add(new PrimitiveType("class")); } else if (tp.HasValueTypeConstraint) {