Browse Source

Fix #3079: Replace parameter names that consist of only whitespace

pull/3081/head
Siegfried Pammer 2 years ago
parent
commit
0fc003459f
  1. 5
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  3. 3
      ICSharpCode.Decompiler/IL/ILReader.cs
  4. 8
      ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs

5
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -30,7 +30,6 @@ using ICSharpCode.Decompiler; @@ -30,7 +30,6 @@ using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching;
using ICSharpCode.Decompiler.CSharp.Transforms;
using ICSharpCode.Decompiler.DebugInfo;
using ICSharpCode.Decompiler.Disassembler;
@ -1270,9 +1269,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1270,9 +1269,9 @@ namespace ICSharpCode.Decompiler.CSharp
int i = 0;
foreach (var parameter in entity.GetChildrenByRole(Roles.Parameter))
{
if (string.IsNullOrEmpty(parameter.Name) && !parameter.Type.IsArgList())
if (string.IsNullOrWhiteSpace(parameter.Name) && !parameter.Type.IsArgList())
{
// needs to be consistent with logic in ILReader.CreateILVarable(ParameterDefinition)
// needs to be consistent with logic in ILReader.CreateILVarable
parameter.Name = "P_" + i;
}
i++;

3
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -26,6 +26,7 @@ using System.Text; @@ -26,6 +26,7 @@ using System.Text;
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.IL.Transforms;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
@ -781,7 +782,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -781,7 +782,7 @@ namespace ICSharpCode.Decompiler.CSharp
argumentNames = new string[method.Parameters.Count];
}
parameter = method.Parameters[argumentToParameterMap[i]];
if (argumentNames != null)
if (argumentNames != null && AssignVariableNames.IsValidName(parameter.Name))
{
argumentNames[arguments.Count] = parameter.Name;
}

3
ICSharpCode.Decompiler/IL/ILReader.cs

@ -19,7 +19,6 @@ @@ -19,7 +19,6 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
@ -334,7 +333,7 @@ namespace ICSharpCode.Decompiler.IL @@ -334,7 +333,7 @@ namespace ICSharpCode.Decompiler.IL
Debug.Assert(ilVar.StoreCount == 1); // count the initial store when the method is called with an argument
if (index < 0)
ilVar.Name = "this";
else if (string.IsNullOrEmpty(name))
else if (string.IsNullOrWhiteSpace(name))
ilVar.Name = "P_" + index;
else
ilVar.Name = name;

8
ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs

@ -202,7 +202,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -202,7 +202,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{
switch (v.Kind)
{
case VariableKind.Parameter: // ignore
case VariableKind.Parameter:
// Parameter names are handled in ILReader.CreateILVariable
// and CSharpDecompiler.FixParameterNames
break;
case VariableKind.InitializerTarget: // keep generated names
AddExistingName(reservedVariableNames, v.Name);
@ -326,9 +328,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -326,9 +328,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false;
}
static bool IsValidName(string varName)
internal static bool IsValidName(string varName)
{
if (string.IsNullOrEmpty(varName))
if (string.IsNullOrWhiteSpace(varName))
return false;
if (!(char.IsLetter(varName[0]) || varName[0] == '_'))
return false;

Loading…
Cancel
Save