185 lines
5.0 KiB
C#
185 lines
5.0 KiB
C#
using System.Collections.Immutable;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
|
|
|
internal sealed class AnalyzedArguments
|
|
{
|
|
public readonly ArrayBuilder<BoundExpression> Arguments;
|
|
|
|
public readonly ArrayBuilder<(string Name, Location Location)?> Names;
|
|
|
|
public readonly ArrayBuilder<RefKind> RefKinds;
|
|
|
|
public bool IsExtensionMethodInvocation;
|
|
|
|
private ThreeState _lazyHasDynamicArgument;
|
|
|
|
public static readonly ObjectPool<AnalyzedArguments> Pool = CreatePool();
|
|
|
|
public bool HasDynamicArgument
|
|
{
|
|
get
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
|
|
if (ThreeStateHelpers.HasValue(_lazyHasDynamicArgument))
|
|
{
|
|
return ThreeStateHelpers.Value(_lazyHasDynamicArgument);
|
|
}
|
|
bool flag = RefKinds.Count > 0;
|
|
for (int i = 0; i < Arguments.Count; i++)
|
|
{
|
|
BoundExpression boundExpression = Arguments[i];
|
|
if ((object)boundExpression.Type != null && boundExpression.Type.IsDynamic() && (!flag || (int)RefKinds[i] == 0))
|
|
{
|
|
_lazyHasDynamicArgument = (ThreeState)2;
|
|
return true;
|
|
}
|
|
}
|
|
_lazyHasDynamicArgument = (ThreeState)1;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool HasErrors
|
|
{
|
|
get
|
|
{
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
Enumerator<BoundExpression> enumerator = Arguments.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
if (enumerator.Current.HasAnyErrors)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal AnalyzedArguments()
|
|
{
|
|
Arguments = new ArrayBuilder<BoundExpression>(32);
|
|
Names = new ArrayBuilder<(string, Location)?>(32);
|
|
RefKinds = new ArrayBuilder<RefKind>(32);
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
|
Arguments.Clear();
|
|
Names.Clear();
|
|
RefKinds.Clear();
|
|
IsExtensionMethodInvocation = false;
|
|
_lazyHasDynamicArgument = (ThreeState)0;
|
|
}
|
|
|
|
public BoundExpression Argument(int i)
|
|
{
|
|
return Arguments[i];
|
|
}
|
|
|
|
public void AddName(IdentifierNameSyntax name)
|
|
{
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
ArrayBuilder<(string Name, Location Location)?> names = Names;
|
|
SyntaxToken identifier = name.Identifier;
|
|
names.Add(((string, Location)?)(((SyntaxToken)(ref identifier)).ValueText, ((SyntaxNode)name).Location));
|
|
}
|
|
|
|
public string? Name(int i)
|
|
{
|
|
if (Names.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
return Names[i]?.Item1;
|
|
}
|
|
|
|
public ImmutableArray<string?> GetNames()
|
|
{
|
|
if (Names.Count == 0)
|
|
{
|
|
return default(ImmutableArray<string>);
|
|
}
|
|
ArrayBuilder<string> instance = ArrayBuilder<string>.GetInstance(Names.Count);
|
|
for (int i = 0; i < Names.Count; i++)
|
|
{
|
|
instance.Add(Name(i));
|
|
}
|
|
return instance.ToImmutableAndFree();
|
|
}
|
|
|
|
public RefKind RefKind(int i)
|
|
{
|
|
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
|
|
if (RefKinds.Count <= 0)
|
|
{
|
|
return (RefKind)0;
|
|
}
|
|
return RefKinds[i];
|
|
}
|
|
|
|
public bool IsExtensionMethodThisArgument(int i)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
return IsExtensionMethodInvocation;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static AnalyzedArguments GetInstance()
|
|
{
|
|
return Pool.Allocate();
|
|
}
|
|
|
|
public static AnalyzedArguments GetInstance(AnalyzedArguments original)
|
|
{
|
|
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
|
|
AnalyzedArguments instance = GetInstance();
|
|
instance.Arguments.AddRange(original.Arguments);
|
|
instance.Names.AddRange(original.Names);
|
|
instance.RefKinds.AddRange(original.RefKinds);
|
|
instance.IsExtensionMethodInvocation = original.IsExtensionMethodInvocation;
|
|
instance._lazyHasDynamicArgument = original._lazyHasDynamicArgument;
|
|
return instance;
|
|
}
|
|
|
|
public static AnalyzedArguments GetInstance(ImmutableArray<BoundExpression> arguments, ImmutableArray<RefKind> argumentRefKindsOpt, ImmutableArray<(string, Location)?> argumentNamesOpt)
|
|
{
|
|
AnalyzedArguments instance = GetInstance();
|
|
instance.Arguments.AddRange(arguments);
|
|
if (!argumentRefKindsOpt.IsDefault)
|
|
{
|
|
instance.RefKinds.AddRange(argumentRefKindsOpt);
|
|
}
|
|
if (!argumentNamesOpt.IsDefault)
|
|
{
|
|
instance.Names.AddRange(argumentNamesOpt);
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
public void Free()
|
|
{
|
|
Clear();
|
|
Pool.Free(this);
|
|
}
|
|
|
|
private static ObjectPool<AnalyzedArguments> CreatePool()
|
|
{
|
|
return new ObjectPool<AnalyzedArguments>((Factory<AnalyzedArguments>)(() => new AnalyzedArguments()), 10, true);
|
|
}
|
|
}
|