59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
|
|
|
internal class UnassignedVariablesWalker : DefiniteAssignmentPass
|
|
{
|
|
private readonly HashSet<Symbol> _result = new HashSet<Symbol>();
|
|
|
|
private UnassignedVariablesWalker(CSharpCompilation compilation, Symbol member, BoundNode node)
|
|
: base(compilation, member, node, EmptyStructTypeCache.CreateNeverEmpty())
|
|
{
|
|
}
|
|
|
|
internal static HashSet<Symbol> Analyze(CSharpCompilation compilation, Symbol member, BoundNode node, bool convertInsufficientExecutionStackExceptionToCancelledByStackGuardException = false)
|
|
{
|
|
UnassignedVariablesWalker unassignedVariablesWalker = new UnassignedVariablesWalker(compilation, member, node);
|
|
if (convertInsufficientExecutionStackExceptionToCancelledByStackGuardException)
|
|
{
|
|
unassignedVariablesWalker._convertInsufficientExecutionStackExceptionToCancelledByStackGuardException = true;
|
|
}
|
|
try
|
|
{
|
|
bool badRegion = false;
|
|
HashSet<Symbol> hashSet = unassignedVariablesWalker.Analyze(ref badRegion);
|
|
return badRegion ? new HashSet<Symbol>() : hashSet;
|
|
}
|
|
finally
|
|
{
|
|
unassignedVariablesWalker.Free();
|
|
}
|
|
}
|
|
|
|
private HashSet<Symbol> Analyze(ref bool badRegion)
|
|
{
|
|
Analyze(ref badRegion, null);
|
|
return _result;
|
|
}
|
|
|
|
protected override void ReportUnassigned(Symbol symbol, SyntaxNode node, int slot, bool skipIfUseBeforeDeclaration)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Invalid comparison between Unknown and I4
|
|
if ((int)symbol.Kind != 6)
|
|
{
|
|
_result.Add(symbol);
|
|
return;
|
|
}
|
|
_result.Add(GetNonMemberSymbol(slot));
|
|
base.ReportUnassigned(symbol, node, slot, skipIfUseBeforeDeclaration);
|
|
}
|
|
|
|
protected override void ReportUnassignedOutParameter(ParameterSymbol parameter, SyntaxNode node, Location location)
|
|
{
|
|
_result.Add(parameter);
|
|
base.ReportUnassignedOutParameter(parameter, node, location);
|
|
}
|
|
}
|