207 lines
8.3 KiB
C#
207 lines
8.3 KiB
C#
using System.Collections.Immutable;
|
|
using System.Threading;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal abstract class SourceParameterSymbol : SourceParameterSymbolBase
|
|
{
|
|
protected SymbolCompletionState state;
|
|
|
|
protected readonly TypeWithAnnotations parameterType;
|
|
|
|
private readonly string _name;
|
|
|
|
private readonly Location? _location;
|
|
|
|
private readonly RefKind _refKind;
|
|
|
|
private readonly ScopedKind _scope;
|
|
|
|
internal sealed override bool RequiresCompletion => true;
|
|
|
|
internal abstract bool HasOptionalAttribute { get; }
|
|
|
|
internal abstract bool HasDefaultArgumentSyntax { get; }
|
|
|
|
internal abstract SyntaxList<AttributeListSyntax> AttributeDeclarationList { get; }
|
|
|
|
internal abstract SyntaxReference SyntaxReference { get; }
|
|
|
|
internal abstract bool IsExtensionMethodThis { get; }
|
|
|
|
public sealed override RefKind RefKind => _refKind;
|
|
|
|
internal ScopedKind DeclaredScope => _scope;
|
|
|
|
internal abstract override ScopedKind EffectiveScope { get; }
|
|
|
|
internal sealed override bool UseUpdatedEscapeRules => ContainingModule.UseUpdatedEscapeRules;
|
|
|
|
public sealed override string Name => _name;
|
|
|
|
public sealed override ImmutableArray<Location> Locations
|
|
{
|
|
get
|
|
{
|
|
if (_location != null)
|
|
{
|
|
return ImmutableArray.Create<Location>(_location);
|
|
}
|
|
return ImmutableArray<Location>.Empty;
|
|
}
|
|
}
|
|
|
|
public sealed override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
|
|
{
|
|
get
|
|
{
|
|
if (!IsImplicitlyDeclared)
|
|
{
|
|
return Symbol.GetDeclaringSyntaxReferenceHelper<ParameterSyntax>(Locations);
|
|
}
|
|
return ImmutableArray<SyntaxReference>.Empty;
|
|
}
|
|
}
|
|
|
|
public sealed override TypeWithAnnotations TypeWithAnnotations => parameterType;
|
|
|
|
public override bool IsImplicitlyDeclared
|
|
{
|
|
get
|
|
{
|
|
if (ContainingSymbol is MethodSymbol methodSymbol)
|
|
{
|
|
return methodSymbol.IsAccessor();
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal override bool IsMetadataIn
|
|
{
|
|
get
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000b: Invalid comparison between Unknown and I4
|
|
RefKind refKind = RefKind;
|
|
if (refKind - 3 <= 1)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal override bool IsMetadataOut => (int)RefKind == 2;
|
|
|
|
public static SourceParameterSymbol Create(Binder context, Symbol owner, TypeWithAnnotations parameterType, ParameterSyntax syntax, RefKind refKind, SyntaxToken identifier, int ordinal, bool isParams, bool isExtensionMethodThis, bool addRefReadOnlyModifier, ScopedKind scope, BindingDiagnosticBag declarationDiagnostics)
|
|
{
|
|
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0010: Expected O, but got Unknown
|
|
//IL_0030: 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)
|
|
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
|
|
string valueText = ((SyntaxToken)(ref identifier)).ValueText;
|
|
SourceLocation location = new SourceLocation(ref identifier);
|
|
if (isParams)
|
|
{
|
|
Binder.ReportUseSiteDiagnosticForSynthesizedAttribute(context.Compilation, (WellKnownMember)63, declarationDiagnostics, ((SyntaxToken)(ref identifier)).Parent.GetLocation());
|
|
}
|
|
ImmutableArray<CustomModifier> refCustomModifiers = ParameterHelpers.ConditionallyCreateInModifiers(refKind, addRefReadOnlyModifier, context, declarationDiagnostics, (SyntaxNode)(object)syntax);
|
|
if (!refCustomModifiers.IsDefaultOrEmpty)
|
|
{
|
|
return new SourceComplexParameterSymbolWithCustomModifiersPrecedingRef(owner, ordinal, parameterType, refKind, refCustomModifiers, valueText, (Location)(object)location, syntax.GetReference(), isParams, isExtensionMethodThis, scope);
|
|
}
|
|
if (!isParams && !isExtensionMethodThis && syntax.Default == null && syntax.AttributeLists.Count == 0 && !owner.IsPartialMethod())
|
|
{
|
|
return new SourceSimpleParameterSymbol(owner, parameterType, ordinal, refKind, scope, valueText, (Location?)(object)location);
|
|
}
|
|
return new SourceComplexParameterSymbol(owner, ordinal, parameterType, refKind, valueText, (Location)(object)location, syntax.GetReference(), isParams, isExtensionMethodThis, scope);
|
|
}
|
|
|
|
protected SourceParameterSymbol(Symbol owner, TypeWithAnnotations parameterType, int ordinal, RefKind refKind, ScopedKind scope, string name, Location location)
|
|
: base(owner, ordinal)
|
|
{
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
|
|
this.parameterType = parameterType;
|
|
_refKind = refKind;
|
|
_scope = scope;
|
|
_name = name;
|
|
_location = location;
|
|
}
|
|
|
|
internal override ParameterSymbol WithCustomModifiersAndParams(TypeSymbol newType, ImmutableArray<CustomModifier> newCustomModifiers, ImmutableArray<CustomModifier> newRefCustomModifiers, bool newIsParams)
|
|
{
|
|
return WithCustomModifiersAndParamsCore(newType, newCustomModifiers, newRefCustomModifiers, newIsParams);
|
|
}
|
|
|
|
internal SourceParameterSymbol WithCustomModifiersAndParamsCore(TypeSymbol newType, ImmutableArray<CustomModifier> newCustomModifiers, ImmutableArray<CustomModifier> newRefCustomModifiers, bool newIsParams)
|
|
{
|
|
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
|
|
newType = CustomModifierUtils.CopyTypeCustomModifiers(newType, base.Type, ContainingAssembly);
|
|
TypeWithAnnotations typeWithAnnotations = TypeWithAnnotations.WithTypeAndModifiers(newType, newCustomModifiers);
|
|
if (newRefCustomModifiers.IsEmpty)
|
|
{
|
|
return new SourceComplexParameterSymbol(ContainingSymbol, Ordinal, typeWithAnnotations, _refKind, _name, _location, SyntaxReference, newIsParams, IsExtensionMethodThis, DeclaredScope);
|
|
}
|
|
return new SourceComplexParameterSymbolWithCustomModifiersPrecedingRef(ContainingSymbol, Ordinal, typeWithAnnotations, _refKind, newRefCustomModifiers, _name, _location, SyntaxReference, newIsParams, IsExtensionMethodThis, DeclaredScope);
|
|
}
|
|
|
|
internal sealed override bool HasComplete(CompletionPart part)
|
|
{
|
|
return state.HasComplete(part);
|
|
}
|
|
|
|
internal override void ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken)
|
|
{
|
|
state.DefaultForceComplete(this, cancellationToken);
|
|
}
|
|
|
|
internal abstract CustomAttributesBag<CSharpAttributeData> GetAttributesBag();
|
|
|
|
public sealed override ImmutableArray<CSharpAttributeData> GetAttributes()
|
|
{
|
|
return GetAttributesBag().Attributes;
|
|
}
|
|
|
|
internal override void AddDeclarationDiagnostics(BindingDiagnosticBag diagnostics)
|
|
{
|
|
ContainingSymbol.AddDeclarationDiagnostics(diagnostics);
|
|
}
|
|
|
|
protected ScopedKind CalculateEffectiveScopeIgnoringAttributes()
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
|
|
ScopedKind declaredScope = DeclaredScope;
|
|
if ((int)declaredScope != 0 || !ParameterHelpers.IsRefScopedByDefault(this))
|
|
{
|
|
return declaredScope;
|
|
}
|
|
return (ScopedKind)1;
|
|
}
|
|
|
|
public override Location? TryGetFirstLocation()
|
|
{
|
|
return _location;
|
|
}
|
|
}
|