1478 lines
65 KiB
C#
1478 lines
65 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading;
|
|
using Microsoft.Cci;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
|
using Microsoft.CodeAnalysis.Symbols;
|
|
using Microsoft.CodeAnalysis.Text;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal abstract class SourceMethodSymbolWithAttributes : SourceMethodSymbol, IAttributeTargetSymbol
|
|
{
|
|
private CustomAttributesBag<CSharpAttributeData> _lazyCustomAttributesBag;
|
|
|
|
private CustomAttributesBag<CSharpAttributeData> _lazyReturnTypeCustomAttributesBag;
|
|
|
|
protected readonly SyntaxReference syntaxReferenceOpt;
|
|
|
|
internal virtual Binder? OuterBinder => null;
|
|
|
|
internal virtual Binder? WithTypeParametersBinder => null;
|
|
|
|
internal SyntaxReference SyntaxRef => syntaxReferenceOpt;
|
|
|
|
internal virtual CSharpSyntaxNode SyntaxNode
|
|
{
|
|
get
|
|
{
|
|
if (syntaxReferenceOpt != null)
|
|
{
|
|
return (CSharpSyntaxNode)(object)syntaxReferenceOpt.GetSyntax(default(CancellationToken));
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
internal SyntaxTree SyntaxTree
|
|
{
|
|
get
|
|
{
|
|
if (syntaxReferenceOpt != null)
|
|
{
|
|
return syntaxReferenceOpt.SyntaxTree;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
|
|
{
|
|
get
|
|
{
|
|
if (syntaxReferenceOpt != null)
|
|
{
|
|
return ImmutableArray.Create<SyntaxReference>(syntaxReferenceOpt);
|
|
}
|
|
return ImmutableArray<SyntaxReference>.Empty;
|
|
}
|
|
}
|
|
|
|
public override FlowAnalysisAnnotations ReturnTypeFlowAnalysisAnnotations => DecodeReturnTypeAnnotationAttributes(GetDecodedReturnTypeWellKnownAttributeData());
|
|
|
|
public override ImmutableHashSet<string> ReturnNotNullIfParameterNotNull => GetDecodedReturnTypeWellKnownAttributeData()?.NotNullIfParameterNotNull ?? ImmutableHashSet<string>.Empty;
|
|
|
|
protected virtual SourceMemberMethodSymbol BoundAttributesSource => null;
|
|
|
|
protected virtual IAttributeTargetSymbol AttributeOwner => this;
|
|
|
|
protected virtual AttributeLocation AttributeLocationForLoadAndValidateAttributes => AttributeLocation.None;
|
|
|
|
IAttributeTargetSymbol IAttributeTargetSymbol.AttributesOwner => AttributeOwner;
|
|
|
|
AttributeLocation IAttributeTargetSymbol.DefaultAttributeLocation => AttributeLocation.Method;
|
|
|
|
AttributeLocation IAttributeTargetSymbol.AllowedAttributeLocations
|
|
{
|
|
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_002b: Expected I4, but got Unknown
|
|
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002e: Invalid comparison between Unknown and I4
|
|
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0033: Invalid comparison between Unknown and I4
|
|
MethodKind methodKind = MethodKind;
|
|
switch (methodKind - 1)
|
|
{
|
|
default:
|
|
if ((int)methodKind != 12)
|
|
{
|
|
if ((int)methodKind != 14)
|
|
{
|
|
break;
|
|
}
|
|
goto case 0;
|
|
}
|
|
goto case 4;
|
|
case 0:
|
|
case 3:
|
|
return AttributeLocation.Method;
|
|
case 4:
|
|
case 6:
|
|
return AttributeLocation.Method | AttributeLocation.Parameter | AttributeLocation.Return;
|
|
case 1:
|
|
case 2:
|
|
case 5:
|
|
break;
|
|
}
|
|
return AttributeLocation.Method | AttributeLocation.Return;
|
|
}
|
|
}
|
|
|
|
public override bool AreLocalsZeroed
|
|
{
|
|
get
|
|
{
|
|
MethodWellKnownAttributeData decodedWellKnownAttributeData = GetDecodedWellKnownAttributeData();
|
|
if (decodedWellKnownAttributeData == null || !decodedWellKnownAttributeData.HasSkipLocalsInitAttribute)
|
|
{
|
|
return base.AreContainingSymbolLocalsZeroed;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal sealed override ObsoleteAttributeData ObsoleteAttributeData
|
|
{
|
|
get
|
|
{
|
|
if (ContainingSymbol is SourceMemberContainerTypeSymbol { AnyMemberHasAttributes: false })
|
|
{
|
|
return null;
|
|
}
|
|
CustomAttributesBag<CSharpAttributeData> lazyCustomAttributesBag = _lazyCustomAttributesBag;
|
|
if (lazyCustomAttributesBag != null && lazyCustomAttributesBag.IsEarlyDecodedWellKnownAttributeDataComputed)
|
|
{
|
|
MethodEarlyWellKnownAttributeData methodEarlyWellKnownAttributeData = (MethodEarlyWellKnownAttributeData)(object)lazyCustomAttributesBag.EarlyDecodedWellKnownAttributeData;
|
|
if (methodEarlyWellKnownAttributeData == null)
|
|
{
|
|
return null;
|
|
}
|
|
return ((CommonMethodEarlyWellKnownAttributeData)methodEarlyWellKnownAttributeData).ObsoleteAttributeData;
|
|
}
|
|
if (syntaxReferenceOpt == null)
|
|
{
|
|
return null;
|
|
}
|
|
return ObsoleteAttributeData.Uninitialized;
|
|
}
|
|
}
|
|
|
|
internal override ImmutableArray<string> NotNullMembers => GetDecodedWellKnownAttributeData()?.NotNullMembers ?? ImmutableArray<string>.Empty;
|
|
|
|
internal override ImmutableArray<string> NotNullWhenTrueMembers => GetDecodedWellKnownAttributeData()?.NotNullWhenTrueMembers ?? ImmutableArray<string>.Empty;
|
|
|
|
internal override ImmutableArray<string> NotNullWhenFalseMembers => GetDecodedWellKnownAttributeData()?.NotNullWhenFalseMembers ?? ImmutableArray<string>.Empty;
|
|
|
|
public override FlowAnalysisAnnotations FlowAnalysisAnnotations => DecodeFlowAnalysisAttributes(GetDecodedWellKnownAttributeData());
|
|
|
|
internal sealed override bool HasUnscopedRefAttribute => GetDecodedWellKnownAttributeData()?.HasUnscopedRefAttribute ?? false;
|
|
|
|
public sealed override bool HidesBaseMethodsByName => false;
|
|
|
|
internal sealed override bool HasRuntimeSpecialName
|
|
{
|
|
get
|
|
{
|
|
if (!base.HasRuntimeSpecialName)
|
|
{
|
|
return IsVtableGapInterfaceMethod();
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
internal override bool HasSpecialName
|
|
{
|
|
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_0047: Expected I4, but got Unknown
|
|
MethodKind methodKind = MethodKind;
|
|
switch (methodKind - 1)
|
|
{
|
|
case 0:
|
|
case 1:
|
|
case 4:
|
|
case 6:
|
|
case 8:
|
|
case 10:
|
|
case 11:
|
|
case 13:
|
|
return true;
|
|
default:
|
|
{
|
|
if (IsVtableGapInterfaceMethod())
|
|
{
|
|
return true;
|
|
}
|
|
MethodWellKnownAttributeData decodedWellKnownAttributeData = GetDecodedWellKnownAttributeData();
|
|
if (decodedWellKnownAttributeData != null)
|
|
{
|
|
return ((CommonMethodWellKnownAttributeData)decodedWellKnownAttributeData).HasSpecialNameAttribute;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
internal sealed override bool IsDirectlyExcludedFromCodeCoverage
|
|
{
|
|
get
|
|
{
|
|
MethodWellKnownAttributeData decodedWellKnownAttributeData = GetDecodedWellKnownAttributeData();
|
|
if (decodedWellKnownAttributeData == null)
|
|
{
|
|
return false;
|
|
}
|
|
return ((CommonMethodWellKnownAttributeData)decodedWellKnownAttributeData).HasExcludeFromCodeCoverageAttribute;
|
|
}
|
|
}
|
|
|
|
internal override bool RequiresSecurityObject
|
|
{
|
|
get
|
|
{
|
|
MethodWellKnownAttributeData decodedWellKnownAttributeData = GetDecodedWellKnownAttributeData();
|
|
if (decodedWellKnownAttributeData != null)
|
|
{
|
|
return ((CommonMethodWellKnownAttributeData)decodedWellKnownAttributeData).HasDynamicSecurityMethodAttribute;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal override bool HasDeclarativeSecurity
|
|
{
|
|
get
|
|
{
|
|
MethodWellKnownAttributeData decodedWellKnownAttributeData = GetDecodedWellKnownAttributeData();
|
|
if (decodedWellKnownAttributeData != null)
|
|
{
|
|
return ((CommonMethodWellKnownAttributeData)decodedWellKnownAttributeData).HasDeclarativeSecurity;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal override MarshalPseudoCustomAttributeData? ReturnValueMarshallingInformation
|
|
{
|
|
get
|
|
{
|
|
ReturnTypeWellKnownAttributeData decodedReturnTypeWellKnownAttributeData = GetDecodedReturnTypeWellKnownAttributeData();
|
|
if (decodedReturnTypeWellKnownAttributeData == null)
|
|
{
|
|
return null;
|
|
}
|
|
return ((CommonReturnTypeWellKnownAttributeData)decodedReturnTypeWellKnownAttributeData).MarshallingInformation;
|
|
}
|
|
}
|
|
|
|
internal override MethodImplAttributes ImplementationAttributes
|
|
{
|
|
get
|
|
{
|
|
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0028: Invalid comparison between Unknown and I4
|
|
MethodWellKnownAttributeData decodedWellKnownAttributeData = GetDecodedWellKnownAttributeData();
|
|
MethodImplAttributes methodImplAttributes = ((decodedWellKnownAttributeData != null) ? ((CommonMethodWellKnownAttributeData)decodedWellKnownAttributeData).MethodImplAttributes : MethodImplAttributes.IL);
|
|
if (ContainingType.IsComImport && (int)MethodKind == 1)
|
|
{
|
|
methodImplAttributes |= (MethodImplAttributes)4099;
|
|
}
|
|
return methodImplAttributes;
|
|
}
|
|
}
|
|
|
|
protected SourceMethodSymbolWithAttributes(SyntaxReference syntaxReferenceOpt)
|
|
{
|
|
this.syntaxReferenceOpt = syntaxReferenceOpt;
|
|
}
|
|
|
|
protected CSharpSyntaxNode? GetInMethodSyntaxNode()
|
|
{
|
|
CSharpSyntaxNode syntaxNode = SyntaxNode;
|
|
if (!(syntaxNode is ConstructorDeclarationSyntax constructorDeclarationSyntax))
|
|
{
|
|
if (!(syntaxNode is BaseMethodDeclarationSyntax baseMethodDeclarationSyntax))
|
|
{
|
|
if (!(syntaxNode is AccessorDeclarationSyntax accessorDeclarationSyntax))
|
|
{
|
|
if (!(syntaxNode is ArrowExpressionClauseSyntax result))
|
|
{
|
|
if (!(syntaxNode is LocalFunctionStatementSyntax localFunctionStatementSyntax))
|
|
{
|
|
if (!(syntaxNode is CompilationUnitSyntax))
|
|
{
|
|
if (syntaxNode is RecordDeclarationSyntax result2)
|
|
{
|
|
return result2;
|
|
}
|
|
if (syntaxNode is ClassDeclarationSyntax result3)
|
|
{
|
|
return result3;
|
|
}
|
|
}
|
|
else if (this is SynthesizedSimpleProgramEntryPointSymbol synthesizedSimpleProgramEntryPointSymbol)
|
|
{
|
|
return (CSharpSyntaxNode)(object)synthesizedSimpleProgramEntryPointSymbol.ReturnTypeSyntax;
|
|
}
|
|
return null;
|
|
}
|
|
return (CSharpSyntaxNode?)(((object)localFunctionStatementSyntax.Body) ?? ((object)localFunctionStatementSyntax.ExpressionBody));
|
|
}
|
|
return result;
|
|
}
|
|
return (CSharpSyntaxNode?)(((object)accessorDeclarationSyntax.Body) ?? ((object)accessorDeclarationSyntax.ExpressionBody));
|
|
}
|
|
return (CSharpSyntaxNode?)(((object)baseMethodDeclarationSyntax.Body) ?? ((object)baseMethodDeclarationSyntax.ExpressionBody));
|
|
}
|
|
return (CSharpSyntaxNode?)(constructorDeclarationSyntax.Initializer ?? ((object)constructorDeclarationSyntax.Body) ?? ((object)constructorDeclarationSyntax.ExpressionBody));
|
|
}
|
|
|
|
internal virtual OneOrMany<SyntaxList<AttributeListSyntax>> GetAttributeDeclarations()
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: 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)
|
|
return OneOrMany.Create<SyntaxList<AttributeListSyntax>>(default(SyntaxList<AttributeListSyntax>));
|
|
}
|
|
|
|
internal virtual OneOrMany<SyntaxList<AttributeListSyntax>> GetReturnTypeAttributeDeclarations()
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
return GetAttributeDeclarations();
|
|
}
|
|
|
|
internal MethodEarlyWellKnownAttributeData GetEarlyDecodedWellKnownAttributeData()
|
|
{
|
|
CustomAttributesBag<CSharpAttributeData> val = _lazyCustomAttributesBag;
|
|
if (val == null || !val.IsEarlyDecodedWellKnownAttributeDataComputed)
|
|
{
|
|
val = GetAttributesBag();
|
|
}
|
|
return (MethodEarlyWellKnownAttributeData)(object)val.EarlyDecodedWellKnownAttributeData;
|
|
}
|
|
|
|
protected MethodWellKnownAttributeData GetDecodedWellKnownAttributeData()
|
|
{
|
|
CustomAttributesBag<CSharpAttributeData> val = _lazyCustomAttributesBag;
|
|
if (val == null || !val.IsDecodedWellKnownAttributeDataComputed)
|
|
{
|
|
val = GetAttributesBag();
|
|
}
|
|
return (MethodWellKnownAttributeData)(object)val.DecodedWellKnownAttributeData;
|
|
}
|
|
|
|
internal ReturnTypeWellKnownAttributeData GetDecodedReturnTypeWellKnownAttributeData()
|
|
{
|
|
CustomAttributesBag<CSharpAttributeData> val = _lazyReturnTypeCustomAttributesBag;
|
|
if (val == null || !val.IsDecodedWellKnownAttributeDataComputed)
|
|
{
|
|
val = GetReturnTypeAttributesBag();
|
|
}
|
|
return (ReturnTypeWellKnownAttributeData)(object)val.DecodedWellKnownAttributeData;
|
|
}
|
|
|
|
private CustomAttributesBag<CSharpAttributeData> GetAttributesBag()
|
|
{
|
|
CustomAttributesBag<CSharpAttributeData> lazyCustomAttributesBag = _lazyCustomAttributesBag;
|
|
if (lazyCustomAttributesBag != null && lazyCustomAttributesBag.IsSealed)
|
|
{
|
|
return lazyCustomAttributesBag;
|
|
}
|
|
return GetAttributesBag(ref _lazyCustomAttributesBag, forReturnType: false);
|
|
}
|
|
|
|
private CustomAttributesBag<CSharpAttributeData> GetReturnTypeAttributesBag()
|
|
{
|
|
CustomAttributesBag<CSharpAttributeData> lazyReturnTypeCustomAttributesBag = _lazyReturnTypeCustomAttributesBag;
|
|
if (lazyReturnTypeCustomAttributesBag != null && lazyReturnTypeCustomAttributesBag.IsSealed)
|
|
{
|
|
return lazyReturnTypeCustomAttributesBag;
|
|
}
|
|
return GetAttributesBag(ref _lazyReturnTypeCustomAttributesBag, forReturnType: true);
|
|
}
|
|
|
|
private CustomAttributesBag<CSharpAttributeData> GetAttributesBag(ref CustomAttributesBag<CSharpAttributeData> lazyCustomAttributesBag, bool forReturnType)
|
|
{
|
|
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
|
|
SourceMemberMethodSymbol boundAttributesSource = BoundAttributesSource;
|
|
bool flag;
|
|
if ((object)boundAttributesSource != null)
|
|
{
|
|
CustomAttributesBag<CSharpAttributeData> value = (forReturnType ? boundAttributesSource.GetReturnTypeAttributesBag() : boundAttributesSource.GetAttributesBag());
|
|
flag = Interlocked.CompareExchange(ref lazyCustomAttributesBag, value, null) == null;
|
|
}
|
|
else
|
|
{
|
|
AttributeLocation symbolPart;
|
|
OneOrMany<SyntaxList<AttributeListSyntax>> attributesSyntaxLists;
|
|
if (!forReturnType)
|
|
{
|
|
OneOrMany<SyntaxList<AttributeListSyntax>> attributeDeclarations = GetAttributeDeclarations();
|
|
AttributeLocation attributeLocationForLoadAndValidateAttributes = AttributeLocationForLoadAndValidateAttributes;
|
|
symbolPart = attributeLocationForLoadAndValidateAttributes;
|
|
attributesSyntaxLists = attributeDeclarations;
|
|
}
|
|
else
|
|
{
|
|
OneOrMany<SyntaxList<AttributeListSyntax>> returnTypeAttributeDeclarations = GetReturnTypeAttributeDeclarations();
|
|
symbolPart = AttributeLocation.Return;
|
|
attributesSyntaxLists = returnTypeAttributeDeclarations;
|
|
}
|
|
flag = LoadAndValidateAttributes(attributesSyntaxLists, ref lazyCustomAttributesBag, symbolPart, earlyDecodingOnly: false, OuterBinder);
|
|
}
|
|
if (flag)
|
|
{
|
|
NoteAttributesComplete(forReturnType);
|
|
}
|
|
return lazyCustomAttributesBag;
|
|
}
|
|
|
|
protected abstract void NoteAttributesComplete(bool forReturnType);
|
|
|
|
public override ImmutableArray<CSharpAttributeData> GetAttributes()
|
|
{
|
|
return GetAttributesBag().Attributes;
|
|
}
|
|
|
|
public override ImmutableArray<CSharpAttributeData> GetReturnTypeAttributes()
|
|
{
|
|
return GetReturnTypeAttributesBag().Attributes;
|
|
}
|
|
|
|
internal override (CSharpAttributeData?, BoundAttribute?) EarlyDecodeWellKnownAttribute(ref EarlyDecodeWellKnownAttributeArguments<EarlyWellKnownAttributeBinder, NamedTypeSymbol, AttributeSyntax, AttributeLocation> arguments)
|
|
{
|
|
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
|
|
if (arguments.SymbolPart == AttributeLocation.None)
|
|
{
|
|
if (CSharpAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.ConditionalAttribute))
|
|
{
|
|
var (cSharpAttributeData, item) = arguments.Binder.GetAttribute(arguments.AttributeSyntax, arguments.AttributeType, null, null, out var generatedDiagnostics);
|
|
if (!((AttributeData)cSharpAttributeData).HasErrors)
|
|
{
|
|
string constructorArgument = ((AttributeData)cSharpAttributeData).GetConstructorArgument<string>(0, (SpecialType)20);
|
|
((CommonMethodEarlyWellKnownAttributeData)arguments.GetOrCreateData<MethodEarlyWellKnownAttributeData>()).AddConditionalSymbol(constructorArgument);
|
|
if (!generatedDiagnostics)
|
|
{
|
|
return (cSharpAttributeData, item);
|
|
}
|
|
}
|
|
return (null, null);
|
|
}
|
|
if (Symbol.EarlyDecodeDeprecatedOrExperimentalOrObsoleteAttribute(ref arguments, out CSharpAttributeData attributeData, out BoundAttribute boundAttribute, out ObsoleteAttributeData obsoleteData))
|
|
{
|
|
if (obsoleteData != null)
|
|
{
|
|
((CommonMethodEarlyWellKnownAttributeData)arguments.GetOrCreateData<MethodEarlyWellKnownAttributeData>()).ObsoleteAttributeData = obsoleteData;
|
|
}
|
|
return (attributeData, boundAttribute);
|
|
}
|
|
if (CSharpAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.UnmanagedCallersOnlyAttribute))
|
|
{
|
|
arguments.GetOrCreateData<MethodEarlyWellKnownAttributeData>().UnmanagedCallersOnlyAttributePresent = true;
|
|
return (null, null);
|
|
}
|
|
}
|
|
return base.EarlyDecodeWellKnownAttribute(ref arguments);
|
|
}
|
|
|
|
public ImmutableArray<(CSharpAttributeData, BoundAttribute)> BindMethodAttributes()
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
return BindAttributes(GetAttributeDeclarations(), OuterBinder);
|
|
}
|
|
|
|
internal sealed override UnmanagedCallersOnlyAttributeData? GetUnmanagedCallersOnlyAttributeData(bool forceComplete)
|
|
{
|
|
if (syntaxReferenceOpt == null)
|
|
{
|
|
return null;
|
|
}
|
|
if (forceComplete)
|
|
{
|
|
GetAttributes();
|
|
}
|
|
CustomAttributesBag<CSharpAttributeData> lazyCustomAttributesBag = _lazyCustomAttributesBag;
|
|
if (lazyCustomAttributesBag == null || !lazyCustomAttributesBag.IsEarlyDecodedWellKnownAttributeDataComputed)
|
|
{
|
|
return UnmanagedCallersOnlyAttributeData.Uninitialized;
|
|
}
|
|
if (lazyCustomAttributesBag.IsDecodedWellKnownAttributeDataComputed)
|
|
{
|
|
return ((MethodWellKnownAttributeData)(object)lazyCustomAttributesBag.DecodedWellKnownAttributeData)?.UnmanagedCallersOnlyAttributeData;
|
|
}
|
|
MethodEarlyWellKnownAttributeData obj = (MethodEarlyWellKnownAttributeData)(object)lazyCustomAttributesBag.EarlyDecodedWellKnownAttributeData;
|
|
if (obj == null || !obj.UnmanagedCallersOnlyAttributePresent)
|
|
{
|
|
return null;
|
|
}
|
|
return UnmanagedCallersOnlyAttributeData.AttributePresentDataNotBound;
|
|
}
|
|
|
|
internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
|
|
{
|
|
MethodEarlyWellKnownAttributeData earlyDecodedWellKnownAttributeData = GetEarlyDecodedWellKnownAttributeData();
|
|
if (earlyDecodedWellKnownAttributeData == null)
|
|
{
|
|
return ImmutableArray<string>.Empty;
|
|
}
|
|
return ((CommonMethodEarlyWellKnownAttributeData)earlyDecodedWellKnownAttributeData).ConditionalSymbols;
|
|
}
|
|
|
|
protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
if (arguments.SymbolPart == AttributeLocation.None)
|
|
{
|
|
DecodeWellKnownAttributeAppliedToMethod(ref arguments);
|
|
}
|
|
else
|
|
{
|
|
DecodeWellKnownAttributeAppliedToReturnValue(ref arguments);
|
|
}
|
|
}
|
|
|
|
private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
|
|
CSharpAttributeData attribute = arguments.Attribute;
|
|
BindingDiagnosticBag bindingDiagnosticBag = (BindingDiagnosticBag)(object)arguments.Diagnostics;
|
|
if (attribute.IsTargetAttribute(this, AttributeDescription.PreserveSigAttribute))
|
|
{
|
|
((CommonMethodWellKnownAttributeData)arguments.GetOrCreateData<MethodWellKnownAttributeData>()).SetPreserveSignature(arguments.Index);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.MethodImplAttribute))
|
|
{
|
|
AttributeData.DecodeMethodImplAttribute<MethodWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation>(ref arguments, (CommonMessageProvider)(object)MessageProvider.Instance);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.DllImportAttribute))
|
|
{
|
|
DecodeDllImportAttribute(ref arguments);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.SpecialNameAttribute))
|
|
{
|
|
((CommonMethodWellKnownAttributeData)arguments.GetOrCreateData<MethodWellKnownAttributeData>()).HasSpecialNameAttribute = true;
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.ExcludeFromCodeCoverageAttribute))
|
|
{
|
|
((CommonMethodWellKnownAttributeData)arguments.GetOrCreateData<MethodWellKnownAttributeData>()).HasExcludeFromCodeCoverageAttribute = true;
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.ConditionalAttribute))
|
|
{
|
|
ValidateConditionalAttribute(attribute, arguments.AttributeSyntaxOpt, bindingDiagnosticBag);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.SuppressUnmanagedCodeSecurityAttribute))
|
|
{
|
|
((CommonMethodWellKnownAttributeData)arguments.GetOrCreateData<MethodWellKnownAttributeData>()).HasSuppressUnmanagedCodeSecurityAttribute = true;
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.DynamicSecurityMethodAttribute))
|
|
{
|
|
((CommonMethodWellKnownAttributeData)arguments.GetOrCreateData<MethodWellKnownAttributeData>()).HasDynamicSecurityMethodAttribute = true;
|
|
}
|
|
else
|
|
{
|
|
if (VerifyObsoleteAttributeAppliedToMethod(ref arguments, AttributeDescription.ObsoleteAttribute) || VerifyObsoleteAttributeAppliedToMethod(ref arguments, AttributeDescription.DeprecatedAttribute) || ReportExplicitUseOfReservedAttributes(in arguments, ReservedAttributes.IsReadOnlyAttribute | ReservedAttributes.IsUnmanagedAttribute | ReservedAttributes.IsByRefLikeAttribute | ReservedAttributes.NullableContextAttribute | ReservedAttributes.CaseSensitiveExtensionAttribute | ReservedAttributes.RequiresLocationAttribute))
|
|
{
|
|
return;
|
|
}
|
|
if (attribute.IsTargetAttribute(this, AttributeDescription.SecurityCriticalAttribute) || attribute.IsTargetAttribute(this, AttributeDescription.SecuritySafeCriticalAttribute))
|
|
{
|
|
if (IsAsync)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName());
|
|
}
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.SkipLocalsInitAttribute))
|
|
{
|
|
CSharpAttributeData.DecodeSkipLocalsInitAttribute<MethodWellKnownAttributeData>(DeclaringCompilation, ref arguments);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.DoesNotReturnAttribute))
|
|
{
|
|
arguments.GetOrCreateData<MethodWellKnownAttributeData>().HasDoesNotReturnAttribute = true;
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.MemberNotNullAttribute))
|
|
{
|
|
MessageID.IDS_FeatureMemberNotNull.CheckFeatureAvailability(bindingDiagnosticBag, (SyntaxNode)(object)arguments.AttributeSyntaxOpt);
|
|
CSharpAttributeData.DecodeMemberNotNullAttribute<MethodWellKnownAttributeData>((TypeSymbol)ContainingType, ref arguments);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.MemberNotNullWhenAttribute))
|
|
{
|
|
MessageID.IDS_FeatureMemberNotNull.CheckFeatureAvailability(bindingDiagnosticBag, (SyntaxNode)(object)arguments.AttributeSyntaxOpt);
|
|
CSharpAttributeData.DecodeMemberNotNullWhenAttribute<MethodWellKnownAttributeData>((TypeSymbol)ContainingType, ref arguments);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.ModuleInitializerAttribute))
|
|
{
|
|
MessageID.IDS_FeatureModuleInitializers.CheckFeatureAvailability(bindingDiagnosticBag, (SyntaxNode)(object)arguments.AttributeSyntaxOpt);
|
|
DecodeModuleInitializerAttribute(arguments);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.UnmanagedCallersOnlyAttribute))
|
|
{
|
|
DecodeUnmanagedCallersOnlyAttribute(ref arguments);
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.UnscopedRefAttribute))
|
|
{
|
|
if (this.IsValidUnscopedRefAttributeTarget())
|
|
{
|
|
arguments.GetOrCreateData<MethodWellKnownAttributeData>().HasUnscopedRefAttribute = true;
|
|
}
|
|
else
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_UnscopedRefAttributeUnsupportedMemberTarget, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location);
|
|
}
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.InterceptsLocationAttribute))
|
|
{
|
|
DecodeInterceptsLocationAttribute(arguments);
|
|
}
|
|
else
|
|
{
|
|
CSharpCompilation declaringCompilation = DeclaringCompilation;
|
|
if (attribute.IsSecurityAttribute(declaringCompilation))
|
|
{
|
|
attribute.DecodeSecurityAttribute<MethodWellKnownAttributeData>((Symbol)this, declaringCompilation, ref arguments);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static FlowAnalysisAnnotations DecodeFlowAnalysisAttributes(MethodWellKnownAttributeData attributeData)
|
|
{
|
|
if (attributeData == null || !attributeData.HasDoesNotReturnAttribute)
|
|
{
|
|
return FlowAnalysisAnnotations.None;
|
|
}
|
|
return FlowAnalysisAnnotations.DoesNotReturn;
|
|
}
|
|
|
|
private bool VerifyObsoleteAttributeAppliedToMethod(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments, AttributeDescription description)
|
|
{
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
|
|
if (arguments.Attribute.IsTargetAttribute(this, description))
|
|
{
|
|
if (this.IsAccessor())
|
|
{
|
|
BindingDiagnosticBag bindingDiagnosticBag = (BindingDiagnosticBag)(object)arguments.Diagnostics;
|
|
if (this is SourceEventAccessorSymbol)
|
|
{
|
|
AttributeUsageInfo attributeUsageInfo = arguments.Attribute.AttributeClass.GetAttributeUsageInfo();
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_AttributeNotOnEventAccessor, ((SyntaxNode)arguments.AttributeSyntaxOpt.Name).Location, ((AttributeDescription)(ref description)).FullName, ((AttributeUsageInfo)(ref attributeUsageInfo)).GetValidTargetsErrorArgument());
|
|
}
|
|
else
|
|
{
|
|
MessageID.IDS_FeatureObsoleteOnPropertyAccessor.CheckFeatureAvailability(bindingDiagnosticBag, (SyntaxNode)(object)arguments.AttributeSyntaxOpt);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void ValidateConditionalAttribute(CSharpAttributeData attribute, AttributeSyntax node, BindingDiagnosticBag diagnostics)
|
|
{
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0099: Invalid comparison between Unknown and I4
|
|
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_010f: Invalid comparison between Unknown and I4
|
|
if (this.IsAccessor())
|
|
{
|
|
AttributeUsageInfo attributeUsageInfo = attribute.AttributeClass.GetAttributeUsageInfo();
|
|
diagnostics.Add(ErrorCode.ERR_AttributeNotOnAccessor, ((SyntaxNode)node.Name).Location, node.GetErrorDisplayName(), ((AttributeUsageInfo)(ref attributeUsageInfo)).GetValidTargetsErrorArgument());
|
|
return;
|
|
}
|
|
if (ContainingType.IsInterfaceType())
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ConditionalOnInterfaceMethod, ((SyntaxNode)node).Location);
|
|
return;
|
|
}
|
|
if (IsOverride)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ConditionalOnOverride, ((SyntaxNode)node).Location, this);
|
|
return;
|
|
}
|
|
if (!base.CanBeReferencedByName || (int)MethodKind == 4)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ConditionalOnSpecialMethod, ((SyntaxNode)node).Location, this);
|
|
return;
|
|
}
|
|
if (!ReturnsVoid)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ConditionalMustReturnVoid, ((SyntaxNode)node).Location, this);
|
|
return;
|
|
}
|
|
if (HasAnyOutParameter())
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ConditionalWithOutParam, ((SyntaxNode)node).Location, this);
|
|
return;
|
|
}
|
|
if ((object)this != null && (int)MethodKind == 17 && !IsStatic)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ConditionalOnLocalFunction, ((SyntaxNode)node).Location, this);
|
|
return;
|
|
}
|
|
string constructorArgument = ((AttributeData)attribute).GetConstructorArgument<string>(0, (SpecialType)20);
|
|
if (constructorArgument == null || !SyntaxFacts.IsValidIdentifier(constructorArgument))
|
|
{
|
|
CSharpSyntaxNode attributeArgumentSyntax = ((AttributeData)(object)attribute).GetAttributeArgumentSyntax(0, node);
|
|
diagnostics.Add(ErrorCode.ERR_BadArgumentToAttribute, ((SyntaxNode)attributeArgumentSyntax).Location, node.GetErrorDisplayName());
|
|
}
|
|
}
|
|
|
|
private bool HasAnyOutParameter()
|
|
{
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001e: Invalid comparison between Unknown and I4
|
|
ImmutableArray<ParameterSymbol>.Enumerator enumerator = Parameters.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
if ((int)enumerator.Current.RefKind == 2)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void DecodeWellKnownAttributeAppliedToReturnValue(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005d: 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)
|
|
CSharpAttributeData attribute = arguments.Attribute;
|
|
_ = (BindingDiagnosticBag)(object)arguments.Diagnostics;
|
|
if (attribute.IsTargetAttribute(this, AttributeDescription.MarshalAsAttribute))
|
|
{
|
|
MarshalAsAttributeDecoder<ReturnTypeWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation>.Decode(ref arguments, AttributeTargets.ReturnValue, (CommonMessageProvider)(object)MessageProvider.Instance);
|
|
}
|
|
else if (!ReportExplicitUseOfReservedAttributes(in arguments, ReservedAttributes.DynamicAttribute | ReservedAttributes.IsReadOnlyAttribute | ReservedAttributes.IsUnmanagedAttribute | ReservedAttributes.IsByRefLikeAttribute | ReservedAttributes.TupleElementNamesAttribute | ReservedAttributes.NullableAttribute | ReservedAttributes.NativeIntegerAttribute | ReservedAttributes.RequiresLocationAttribute))
|
|
{
|
|
if (attribute.IsTargetAttribute(this, AttributeDescription.MaybeNullAttribute))
|
|
{
|
|
arguments.GetOrCreateData<ReturnTypeWellKnownAttributeData>().HasMaybeNullAttribute = true;
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.NotNullAttribute))
|
|
{
|
|
arguments.GetOrCreateData<ReturnTypeWellKnownAttributeData>().HasNotNullAttribute = true;
|
|
}
|
|
else if (attribute.IsTargetAttribute(this, AttributeDescription.NotNullIfNotNullAttribute))
|
|
{
|
|
arguments.GetOrCreateData<ReturnTypeWellKnownAttributeData>().AddNotNullIfParameterNotNull(attribute.DecodeNotNullIfNotNullAttribute());
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DecodeDllImportAttribute(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_031a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_031f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0346: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_034b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0334: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0360: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0365: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
|
|
CSharpAttributeData attribute = arguments.Attribute;
|
|
BindingDiagnosticBag bindingDiagnosticBag = (BindingDiagnosticBag)(object)arguments.Diagnostics;
|
|
bool flag = false;
|
|
MethodSymbol methodSymbol = PartialImplementationPart ?? this;
|
|
if (!methodSymbol.IsExtern || !methodSymbol.IsStatic)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_DllImportOnInvalidMethod, ((SyntaxNode)arguments.AttributeSyntaxOpt.Name).Location);
|
|
flag = true;
|
|
}
|
|
bool flag2 = false;
|
|
MethodSymbol methodSymbol2 = this;
|
|
while ((object)methodSymbol2 != null)
|
|
{
|
|
if (methodSymbol2.IsGenericMethod)
|
|
{
|
|
flag2 = true;
|
|
break;
|
|
}
|
|
methodSymbol2 = methodSymbol2.ContainingSymbol as MethodSymbol;
|
|
}
|
|
if (!flag2)
|
|
{
|
|
NamedTypeSymbol containingType = ContainingType;
|
|
if ((object)containingType == null || !containingType.IsGenericType)
|
|
{
|
|
goto IL_00ad;
|
|
}
|
|
}
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_DllImportOnGenericMethod, ((SyntaxNode)arguments.AttributeSyntaxOpt.Name).Location);
|
|
flag = true;
|
|
goto IL_00ad;
|
|
IL_00ad:
|
|
string text = ((AttributeData)attribute).GetConstructorArgument<string>(0, (SpecialType)20);
|
|
if (!MetadataHelpers.IsValidMetadataIdentifier(text))
|
|
{
|
|
CSharpSyntaxNode attributeArgumentSyntax = ((AttributeData)(object)attribute).GetAttributeArgumentSyntax(0, arguments.AttributeSyntaxOpt);
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InvalidAttributeArgument, ((SyntaxNode)attributeArgumentSyntax).Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName());
|
|
flag = true;
|
|
text = null;
|
|
}
|
|
CharSet charSet = GetEffectiveDefaultMarshallingCharSet() ?? CharSet.None;
|
|
string text2 = null;
|
|
bool flag3 = true;
|
|
CallingConvention callingConvention = System.Runtime.InteropServices.CallingConvention.Winapi;
|
|
bool flag4 = false;
|
|
bool flag5 = false;
|
|
bool? flag6 = null;
|
|
bool? flag7 = null;
|
|
int num = 1;
|
|
ImmutableArray<KeyValuePair<string, TypedConstant>>.Enumerator enumerator = ((AttributeData)attribute).CommonNamedArguments.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
KeyValuePair<string, TypedConstant> current = enumerator.Current;
|
|
TypedConstant value;
|
|
switch (current.Key)
|
|
{
|
|
case "EntryPoint":
|
|
value = current.Value;
|
|
text2 = ((TypedConstant)(ref value)).ValueInternal as string;
|
|
if (!MetadataHelpers.IsValidMetadataIdentifier(text2))
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InvalidNamedArgument, ((SyntaxNode)arguments.AttributeSyntaxOpt.ArgumentList.Arguments[num]).Location, current.Key);
|
|
flag = true;
|
|
text2 = null;
|
|
}
|
|
break;
|
|
case "CharSet":
|
|
value = current.Value;
|
|
charSet = ((TypedConstant)(ref value)).DecodeValue<CharSet>((SpecialType)2);
|
|
break;
|
|
case "SetLastError":
|
|
value = current.Value;
|
|
flag4 = ((TypedConstant)(ref value)).DecodeValue<bool>((SpecialType)7);
|
|
break;
|
|
case "ExactSpelling":
|
|
value = current.Value;
|
|
flag5 = ((TypedConstant)(ref value)).DecodeValue<bool>((SpecialType)7);
|
|
break;
|
|
case "PreserveSig":
|
|
value = current.Value;
|
|
flag3 = ((TypedConstant)(ref value)).DecodeValue<bool>((SpecialType)7);
|
|
break;
|
|
case "CallingConvention":
|
|
value = current.Value;
|
|
callingConvention = ((TypedConstant)(ref value)).DecodeValue<CallingConvention>((SpecialType)2);
|
|
break;
|
|
case "BestFitMapping":
|
|
value = current.Value;
|
|
flag6 = ((TypedConstant)(ref value)).DecodeValue<bool>((SpecialType)7);
|
|
break;
|
|
case "ThrowOnUnmappableChar":
|
|
value = current.Value;
|
|
flag7 = ((TypedConstant)(ref value)).DecodeValue<bool>((SpecialType)7);
|
|
break;
|
|
}
|
|
num++;
|
|
}
|
|
if (!flag)
|
|
{
|
|
((CommonMethodWellKnownAttributeData)arguments.GetOrCreateData<MethodWellKnownAttributeData>()).SetDllImport(arguments.Index, text, text2 ?? Name, DllImportData.MakeFlags(flag5, charSet, flag4, callingConvention, flag6, flag7), flag3);
|
|
}
|
|
}
|
|
|
|
private void DecodeModuleInitializerAttribute(DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0015: Invalid comparison between Unknown and I4
|
|
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
|
|
BindingDiagnosticBag bindingDiagnosticBag = (BindingDiagnosticBag)(object)arguments.Diagnostics;
|
|
if ((int)MethodKind != 10)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_ModuleInitializerMethodMustBeOrdinary, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location);
|
|
return;
|
|
}
|
|
bool flag = false;
|
|
CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = default(CompoundUseSiteInfo<AssemblySymbol>);
|
|
useSiteInfo._002Ector((BindingDiagnosticBag<AssemblySymbol>)(object)bindingDiagnosticBag, ContainingAssembly);
|
|
if (!AccessCheck.IsSymbolAccessible(this, ContainingAssembly, ref useSiteInfo))
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_ModuleInitializerMethodMustBeAccessibleOutsideTopLevelType, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location, Name);
|
|
flag = true;
|
|
}
|
|
((BindingDiagnosticBag<AssemblySymbol>)(object)bindingDiagnosticBag).Add((SyntaxNode)(object)arguments.AttributeSyntaxOpt, useSiteInfo);
|
|
if (!IsStatic || ParameterCount > 0 || !ReturnsVoid || IsAbstract || IsVirtual)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_ModuleInitializerMethodMustBeStaticParameterlessVoid, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location, Name);
|
|
flag = true;
|
|
}
|
|
if (IsGenericMethod || ContainingType.IsGenericType)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_ModuleInitializerMethodAndContainingTypesMustNotBeGeneric, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location, Name);
|
|
flag = true;
|
|
}
|
|
if (_lazyCustomAttributesBag.EarlyDecodedWellKnownAttributeData is MethodEarlyWellKnownAttributeData { UnmanagedCallersOnlyAttributePresent: not false })
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_ModuleInitializerCannotBeUnmanagedCallersOnly, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location);
|
|
flag = true;
|
|
}
|
|
if (!flag && !CallsAreOmitted(arguments.AttributeSyntaxOpt.SyntaxTree))
|
|
{
|
|
DeclaringCompilation.AddModuleInitializerMethod(this);
|
|
}
|
|
}
|
|
|
|
private void DecodeInterceptsLocationAttribute(DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0049: Invalid comparison between Unknown and I4
|
|
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005d: Invalid comparison between Unknown and I4
|
|
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008b: Invalid comparison between Unknown and I4
|
|
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0197: Invalid comparison between Unknown and I4
|
|
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_03af: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_041e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0423: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0425: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0427: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0500: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0504: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0509: Unknown result type (might be due to invalid IL or missing references)
|
|
CSharpAttributeData attribute = arguments.Attribute;
|
|
ImmutableArray<TypedConstant> commonConstructorArguments = ((AttributeData)attribute).CommonConstructorArguments;
|
|
BindingDiagnosticBag bindingDiagnosticBag;
|
|
Location location;
|
|
SyntaxTree val6;
|
|
int num3;
|
|
int num4;
|
|
int num6;
|
|
SyntaxToken val8;
|
|
if (commonConstructorArguments.Length == 3)
|
|
{
|
|
TypedConstant val = commonConstructorArguments[0];
|
|
ITypeSymbol type = ((TypedConstant)(ref val)).Type;
|
|
if (type != null && (int)type.SpecialType == 20)
|
|
{
|
|
TypedConstant val2 = commonConstructorArguments[1];
|
|
if ((int)((TypedConstant)(ref val2)).Kind != 4 && ((TypedConstant)(ref val2)).Value is int num)
|
|
{
|
|
TypedConstant val3 = commonConstructorArguments[2];
|
|
if ((int)((TypedConstant)(ref val3)).Kind != 4 && ((TypedConstant)(ref val3)).Value is int num2)
|
|
{
|
|
bindingDiagnosticBag = (BindingDiagnosticBag)(object)arguments.Diagnostics;
|
|
AttributeSyntax attributeSyntaxOpt = arguments.AttributeSyntaxOpt;
|
|
location = ((SyntaxNode)attributeSyntaxOpt).Location;
|
|
ImmutableArray<ImmutableArray<string>> interceptorsPreviewNamespaces = ((CSharpParseOptions)(object)attributeSyntaxOpt.SyntaxTree.Options).InterceptorsPreviewNamespaces;
|
|
ArrayBuilder<string> thisNamespaceNames = getNamespaceNames();
|
|
if (!interceptorsPreviewNamespaces.Any<ImmutableArray<string>>((ImmutableArray<string> ns) => isDeclaredInNamespace(thisNamespaceNames, ns)))
|
|
{
|
|
reportFeatureNotEnabled(bindingDiagnosticBag, attributeSyntaxOpt, thisNamespaceNames);
|
|
thisNamespaceNames.Free();
|
|
return;
|
|
}
|
|
thisNamespaceNames.Free();
|
|
val3 = commonConstructorArguments[0];
|
|
string text = (string)((TypedConstant)(ref val3)).Value;
|
|
if (text == null)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorFilePathCannotBeNull, ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation(0, attributeSyntaxOpt));
|
|
return;
|
|
}
|
|
if (ContainingType.IsGenericType)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorContainingTypeCannotBeGeneric, location, this);
|
|
return;
|
|
}
|
|
if ((int)MethodKind != 10)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorMethodMustBeOrdinary, location);
|
|
return;
|
|
}
|
|
if (GetUnmanagedCallersOnlyAttributeData(forceComplete: false) != null)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorCannotUseUnmanagedCallersOnly, location);
|
|
return;
|
|
}
|
|
ImmutableArray<SyntaxTree> syntaxTrees = DeclaringCompilation.SyntaxTrees;
|
|
OneOrMany<SyntaxTree> syntaxTreesByMappedPath = DeclaringCompilation.GetSyntaxTreesByMappedPath(text);
|
|
if (syntaxTreesByMappedPath.Count == 0)
|
|
{
|
|
SourceReferenceResolver sourceReferenceResolver = ((CompilationOptions)DeclaringCompilation.Options).SourceReferenceResolver;
|
|
SyntaxTree val4 = ImmutableArrayExtensions.FirstOrDefault<SyntaxTree, string>(syntaxTrees, (Func<SyntaxTree, string, bool>)((SyntaxTree tree, string filePath) => tree.FilePath == filePath), text);
|
|
if (val4 != null)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorPathNotInCompilationWithUnmappedCandidate, ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation(0, attributeSyntaxOpt), text, mapPath(sourceReferenceResolver, val4));
|
|
return;
|
|
}
|
|
SyntaxTree val5 = ImmutableArrayExtensions.FirstOrDefault<SyntaxTree, (SourceReferenceResolver, string)>(syntaxTrees, (Func<SyntaxTree, (SourceReferenceResolver, string), bool>)((SyntaxTree tree, (SourceReferenceResolver referenceResolver, string attributeFilePath) pair) => mapPath(pair.referenceResolver, tree).Replace('\\', '/').EndsWith(pair.attributeFilePath)), (sourceReferenceResolver, text.Replace('\\', '/')));
|
|
if (val5 != null)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorPathNotInCompilationWithCandidate, ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation(0, attributeSyntaxOpt), text, mapPath(sourceReferenceResolver, val5));
|
|
}
|
|
else
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorPathNotInCompilation, ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation(0, attributeSyntaxOpt), text);
|
|
}
|
|
return;
|
|
}
|
|
if (syntaxTreesByMappedPath.Count > 1)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorNonUniquePath, ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation(0, attributeSyntaxOpt), text);
|
|
return;
|
|
}
|
|
val6 = syntaxTreesByMappedPath[0];
|
|
num3 = num - 1;
|
|
num4 = num2 - 1;
|
|
if (num3 < 0 || num4 < 0)
|
|
{
|
|
Location attributeArgumentSyntaxLocation = ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation((num3 < 0) ? 1 : 2, attributeSyntaxOpt);
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorLineCharacterMustBePositive, attributeArgumentSyntaxLocation);
|
|
return;
|
|
}
|
|
TextLineCollection lines = val6.GetText(default(CancellationToken)).Lines;
|
|
int count = lines.Count;
|
|
if (num3 >= count)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorLineOutOfRange, ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation(1, attributeSyntaxOpt), count, num);
|
|
return;
|
|
}
|
|
TextLine val7 = lines[num3];
|
|
int num5 = ((TextLine)(ref val7)).End - ((TextLine)(ref val7)).Start;
|
|
if (num4 >= num5)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorCharacterOutOfRange, ((AttributeData)(object)attribute).GetAttributeArgumentSyntaxLocation(2, attributeSyntaxOpt), num5, num2);
|
|
return;
|
|
}
|
|
num6 = ((TextLine)(ref val7)).Start + num4;
|
|
val8 = val6.GetRoot(default(CancellationToken)).FindToken(num6, false);
|
|
SyntaxToken val9 = val8;
|
|
if (((SyntaxToken)(ref val9)).Parent is SimpleNameSyntax simpleNameSyntax)
|
|
{
|
|
CSharpSyntaxNode parent = simpleNameSyntax.Parent;
|
|
if (parent is MemberAccessExpressionSyntax memberAccessExpressionSyntax)
|
|
{
|
|
if (parent.Parent is InvocationExpressionSyntax && memberAccessExpressionSyntax.Name == simpleNameSyntax)
|
|
{
|
|
goto IL_04e0;
|
|
}
|
|
SimpleNameSyntax simpleNameSyntax2 = simpleNameSyntax;
|
|
if (memberAccessExpressionSyntax.Name != simpleNameSyntax2)
|
|
{
|
|
goto IL_04c0;
|
|
}
|
|
}
|
|
else if (parent is InvocationExpressionSyntax invocationExpressionSyntax)
|
|
{
|
|
SimpleNameSyntax simpleNameSyntax3 = simpleNameSyntax;
|
|
if (invocationExpressionSyntax.Expression == simpleNameSyntax3)
|
|
{
|
|
goto IL_04e0;
|
|
}
|
|
}
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorNameNotInvoked, location, ((SyntaxToken)(ref val8)).Text);
|
|
return;
|
|
}
|
|
goto IL_04c0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs", 957);
|
|
IL_04c0:
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorPositionBadToken, location, ((SyntaxToken)(ref val8)).Text);
|
|
return;
|
|
IL_04e0:
|
|
TextSpan span = ((SyntaxToken)(ref val8)).Span;
|
|
if (num6 != ((TextSpan)(ref span)).Start)
|
|
{
|
|
FileLinePositionSpan lineSpan = ((SyntaxToken)(ref val8)).GetLocation().GetLineSpan();
|
|
LinePosition startLinePosition = ((FileLinePositionSpan)(ref lineSpan)).StartLinePosition;
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_InterceptorMustReferToStartOfTokenPosition, location, ((SyntaxToken)(ref val8)).Text, ((LinePosition)(ref startLinePosition)).Line + 1, ((LinePosition)(ref startLinePosition)).Character + 1);
|
|
}
|
|
else
|
|
{
|
|
DeclaringCompilation.AddInterception(val6.FilePath, num3, num4, location, this);
|
|
}
|
|
ArrayBuilder<string> getNamespaceNames()
|
|
{
|
|
ArrayBuilder<string> instance = ArrayBuilder<string>.GetInstance();
|
|
NamespaceSymbol containingNamespace = ContainingNamespace;
|
|
while ((object)containingNamespace != null && !containingNamespace.IsGlobalNamespace)
|
|
{
|
|
instance.Add(containingNamespace.Name);
|
|
containingNamespace = containingNamespace.ContainingNamespace;
|
|
}
|
|
instance.ReverseContents();
|
|
return instance;
|
|
}
|
|
static bool isDeclaredInNamespace(ArrayBuilder<string> val10, ImmutableArray<string> namespaceSegments)
|
|
{
|
|
if (namespaceSegments.Length == 1 && namespaceSegments[0] == "global")
|
|
{
|
|
return true;
|
|
}
|
|
if (namespaceSegments.Length > val10.Count)
|
|
{
|
|
return false;
|
|
}
|
|
for (int i = 0; i < namespaceSegments.Length; i++)
|
|
{
|
|
if (namespaceSegments[i] != val10[i])
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
static string mapPath(SourceReferenceResolver? referenceResolver, SyntaxTree tree)
|
|
{
|
|
return ((referenceResolver != null) ? referenceResolver.NormalizePath(tree.FilePath, (string)null) : null) ?? tree.FilePath;
|
|
}
|
|
static void reportFeatureNotEnabled(BindingDiagnosticBag diagnostics, AttributeSyntax attributeSyntax, ArrayBuilder<string> namespaceNames)
|
|
{
|
|
if (namespaceNames.Count == 0)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_InterceptorGlobalNamespace, (SyntaxNode)(object)attributeSyntax);
|
|
}
|
|
else
|
|
{
|
|
string text2 = "<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);" + string.Join(".", (IEnumerable<string?>)namespaceNames) + "</InterceptorsPreviewNamespaces>";
|
|
diagnostics.Add(ErrorCode.ERR_InterceptorsFeatureNotEnabled, (SyntaxNode)(object)attributeSyntax, text2);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DecodeUnmanagedCallersOnlyAttribute(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
|
|
BindingDiagnosticBag diagnostics = (BindingDiagnosticBag)(object)arguments.Diagnostics;
|
|
arguments.GetOrCreateData<MethodWellKnownAttributeData>().UnmanagedCallersOnlyAttributeData = DecodeUnmanagedCallersOnlyAttributeData(this, arguments.Attribute, ((SyntaxNode)arguments.AttributeSyntaxOpt).Location, diagnostics);
|
|
CheckAndReportValidUnmanagedCallersOnlyTarget((SyntaxNode?)(object)arguments.AttributeSyntaxOpt.Name, diagnostics);
|
|
CSharpSyntaxNode cSharpSyntaxNode = this.ExtractReturnTypeSyntax();
|
|
if ((object)cSharpSyntaxNode != CSharpSyntaxTree.Dummy.GetRoot(default(CancellationToken)))
|
|
{
|
|
checkAndReportManagedTypes(base.ReturnType, RefKind, (SyntaxNode)(object)cSharpSyntaxNode, isParam: false, diagnostics);
|
|
ImmutableArray<ParameterSymbol>.Enumerator enumerator = Parameters.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
ParameterSymbol current = enumerator.Current;
|
|
checkAndReportManagedTypes(current.Type, current.RefKind, (SyntaxNode)(object)current.GetNonNullSyntaxNode(), isParam: true, diagnostics);
|
|
}
|
|
}
|
|
static UnmanagedCallersOnlyAttributeData DecodeUnmanagedCallersOnlyAttributeData(SourceMethodSymbolWithAttributes @this, CSharpAttributeData attribute, Location location, BindingDiagnosticBag diagnostics2)
|
|
{
|
|
//IL_0049: 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_0083: Unknown result type (might be due to invalid IL or missing references)
|
|
ImmutableHashSet<INamedTypeSymbolInternal> immutableHashSet = null;
|
|
if (!((AttributeData)attribute).CommonNamedArguments.IsDefaultOrEmpty)
|
|
{
|
|
NamedTypeSymbol wellKnownType = @this.DeclaringCompilation.GetWellKnownType((WellKnownType)61);
|
|
ImmutableArray<KeyValuePair<string, TypedConstant>>.Enumerator enumerator2 = ((AttributeData)attribute).CommonNamedArguments.GetEnumerator();
|
|
string text = default(string);
|
|
TypedConstant val = default(TypedConstant);
|
|
while (enumerator2.MoveNext())
|
|
{
|
|
KeyValuePairUtil.Deconstruct<string, TypedConstant>(enumerator2.Current, ref text, ref val);
|
|
string text2 = text;
|
|
TypedConstant value = val;
|
|
bool isField = ImmutableArrayExtensions.Any<Symbol, NamedTypeSymbol>(attribute.AttributeClass.GetMembers(text2), (Func<Symbol, NamedTypeSymbol, bool>)((Symbol m, NamedTypeSymbol systemType) => m is FieldSymbol { Type: ArrayTypeSymbol { ElementType: NamedTypeSymbol elementType } } && elementType.Equals(systemType, (TypeCompareKind)0)), wellKnownType);
|
|
(bool, ImmutableHashSet<INamedTypeSymbolInternal>) tuple = MethodSymbol.TryDecodeUnmanagedCallersOnlyCallConvsField(text2, value, isField, location, diagnostics2);
|
|
if (tuple.Item1)
|
|
{
|
|
immutableHashSet = tuple.Item2;
|
|
}
|
|
}
|
|
}
|
|
return UnmanagedCallersOnlyAttributeData.Create(immutableHashSet);
|
|
}
|
|
static void checkAndReportManagedTypes(TypeSymbol type, RefKind refKind, SyntaxNode syntax, bool isParam, BindingDiagnosticBag bindingDiagnosticBag)
|
|
{
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0021: Invalid comparison between Unknown and I4
|
|
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0025: Invalid comparison between Unknown and I4
|
|
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((int)refKind != 0)
|
|
{
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, syntax.Location);
|
|
}
|
|
ManagedKind managedKindNoUseSiteDiagnostics = type.ManagedKindNoUseSiteDiagnostics;
|
|
if (managedKindNoUseSiteDiagnostics - 1 > 1)
|
|
{
|
|
if ((int)managedKindNoUseSiteDiagnostics != 3)
|
|
{
|
|
throw ExceptionUtilities.UnexpectedValue((object)type.ManagedKindNoUseSiteDiagnostics);
|
|
}
|
|
bindingDiagnosticBag.Add(ErrorCode.ERR_CannotUseManagedTypeInUnmanagedCallersOnly, syntax.Location, type, (isParam ? MessageID.IDS_Parameter : MessageID.IDS_Return).Localize());
|
|
}
|
|
}
|
|
}
|
|
|
|
internal override void PostDecodeWellKnownAttributes(ImmutableArray<CSharpAttributeData> boundAttributes, ImmutableArray<AttributeSyntax> allAttributeSyntaxNodes, BindingDiagnosticBag diagnostics, AttributeLocation symbolPart, WellKnownAttributeData decodedData)
|
|
{
|
|
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002c: Invalid comparison between Unknown and I4
|
|
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0044: Invalid comparison between Unknown and I4
|
|
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0030: Invalid comparison between Unknown and I4
|
|
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0049: Invalid comparison between Unknown and I4
|
|
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d9: Invalid comparison between Unknown and I4
|
|
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00e3: Invalid comparison between Unknown and I4
|
|
if (symbolPart != AttributeLocation.Return)
|
|
{
|
|
if ((ContainingSymbol is NamedTypeSymbol { IsComImport: not false, TypeKind: var typeKind } && ((int)typeKind == 2 || (int)typeKind == 7)) ? true : false)
|
|
{
|
|
MethodKind methodKind = MethodKind;
|
|
if ((int)methodKind == 1 || (int)methodKind == 14)
|
|
{
|
|
if (!IsImplicitlyDeclared)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ComImportWithUserCtor, GetFirstLocation());
|
|
}
|
|
}
|
|
else if (!IsAbstract && !IsExtern)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_ComImportWithImpl, GetFirstLocation(), this, ContainingType);
|
|
}
|
|
}
|
|
if (IsExtern && !IsAbstract && !this.IsPartialMethod() && GetInMethodSyntaxNode() == null && boundAttributes.IsEmpty && !ContainingType.IsComImport)
|
|
{
|
|
ErrorCode code = (((int)MethodKind == 1 || (int)MethodKind == 14) ? ErrorCode.WRN_ExternCtorNoImplementation : ErrorCode.WRN_ExternMethodNoImplementation);
|
|
diagnostics.Add(code, GetFirstLocation(), this);
|
|
}
|
|
}
|
|
base.PostDecodeWellKnownAttributes(boundAttributes, allAttributeSyntaxNodes, diagnostics, symbolPart, decodedData);
|
|
}
|
|
|
|
protected void AsyncMethodChecks(BindingDiagnosticBag diagnostics)
|
|
{
|
|
AsyncMethodChecks(verifyReturnType: true, GetFirstLocation(), diagnostics);
|
|
}
|
|
|
|
protected void AsyncMethodChecks(bool verifyReturnType, Location errorLocation, BindingDiagnosticBag diagnostics)
|
|
{
|
|
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
|
|
if (!IsAsync)
|
|
{
|
|
return;
|
|
}
|
|
bool flag = false;
|
|
TypeSyntax returnTypeSyntax;
|
|
if (verifyReturnType)
|
|
{
|
|
if ((int)RefKind != 0)
|
|
{
|
|
CSharpSyntaxNode syntaxNode = SyntaxNode;
|
|
if (syntaxNode is MethodDeclarationSyntax methodDeclarationSyntax)
|
|
{
|
|
TypeSyntax returnType = methodDeclarationSyntax.ReturnType;
|
|
returnTypeSyntax = returnType;
|
|
}
|
|
else
|
|
{
|
|
if (!(syntaxNode is LocalFunctionStatementSyntax localFunctionStatementSyntax))
|
|
{
|
|
if (syntaxNode is ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpressionSyntax)
|
|
{
|
|
TypeSyntax returnType2 = parenthesizedLambdaExpressionSyntax.ReturnType;
|
|
if (returnType2 != null)
|
|
{
|
|
returnTypeSyntax = returnType2;
|
|
goto IL_0085;
|
|
}
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)syntaxNode);
|
|
}
|
|
TypeSyntax returnType3 = localFunctionStatementSyntax.ReturnType;
|
|
returnTypeSyntax = returnType3;
|
|
}
|
|
goto IL_0085;
|
|
}
|
|
if (isBadAsyncReturn(this))
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_BadAsyncReturn, errorLocation);
|
|
flag = true;
|
|
}
|
|
}
|
|
goto IL_00a8;
|
|
IL_0085:
|
|
SourceMethodSymbol.ReportBadRefToken(returnTypeSyntax, diagnostics);
|
|
flag = true;
|
|
goto IL_00a8;
|
|
IL_00a8:
|
|
if (this.HasAsyncMethodBuilderAttribute(out object _))
|
|
{
|
|
MessageID.IDS_AsyncMethodBuilderOverride.CheckFeatureAvailability(diagnostics, (Compilation)(object)DeclaringCompilation, errorLocation);
|
|
}
|
|
if ((int)MethodKind != 0)
|
|
{
|
|
NamedTypeSymbol containingType = ContainingType;
|
|
while ((object)containingType != null)
|
|
{
|
|
if (containingType is SourceNamedTypeSymbol { HasSecurityCriticalAttributes: not false })
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsyncInClassOrStruct, errorLocation);
|
|
flag = true;
|
|
break;
|
|
}
|
|
containingType = containingType.ContainingType;
|
|
}
|
|
}
|
|
if ((ImplementationAttributes & MethodImplAttributes.Synchronized) != MethodImplAttributes.IL)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_SynchronizedAsyncMethod, errorLocation);
|
|
flag = true;
|
|
}
|
|
if (!flag)
|
|
{
|
|
ReportAsyncParameterErrors(diagnostics, errorLocation);
|
|
}
|
|
NamedTypeSymbol wellKnownType = DeclaringCompilation.GetWellKnownType((WellKnownType)288);
|
|
if (base.ReturnType.OriginalDefinition.Equals(wellKnownType) && GetInMethodSyntaxNode() != null)
|
|
{
|
|
NamedTypeSymbol wellKnownType2 = DeclaringCompilation.GetWellKnownType((WellKnownType)298);
|
|
int num = ImmutableArrayExtensions.Count<ParameterSymbol>(Parameters, (Func<ParameterSymbol, bool>)((ParameterSymbol p) => p.IsSourceParameterWithEnumeratorCancellationAttribute()));
|
|
if (num == 0 && ImmutableArrayExtensions.Any<TypeWithAnnotations, NamedTypeSymbol>(base.ParameterTypesWithAnnotations, (Func<TypeWithAnnotations, NamedTypeSymbol, bool>)((TypeWithAnnotations p, NamedTypeSymbol cancellationTokenType) => p.Type.Equals(cancellationTokenType)), wellKnownType2))
|
|
{
|
|
diagnostics.Add(ErrorCode.WRN_UndecoratedCancellationTokenParameter, errorLocation, this);
|
|
}
|
|
if (num > 1)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_MultipleEnumeratorCancellationAttributes, errorLocation);
|
|
}
|
|
}
|
|
static bool isBadAsyncReturn(MethodSymbol methodSymbol)
|
|
{
|
|
TypeSymbol returnType4 = methodSymbol.ReturnType;
|
|
CSharpCompilation declaringCompilation = methodSymbol.DeclaringCompilation;
|
|
if (!returnType4.IsErrorType() && !returnType4.IsVoidType() && !returnType4.IsIAsyncEnumerableType(declaringCompilation) && !returnType4.IsIAsyncEnumeratorType(declaringCompilation) && !methodSymbol.IsAsyncEffectivelyReturningTask(declaringCompilation))
|
|
{
|
|
return !methodSymbol.IsAsyncEffectivelyReturningGenericTask(declaringCompilation);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static FlowAnalysisAnnotations DecodeReturnTypeAnnotationAttributes(ReturnTypeWellKnownAttributeData attributeData)
|
|
{
|
|
FlowAnalysisAnnotations flowAnalysisAnnotations = FlowAnalysisAnnotations.None;
|
|
if (attributeData != null)
|
|
{
|
|
if (attributeData.HasMaybeNullAttribute)
|
|
{
|
|
flowAnalysisAnnotations |= FlowAnalysisAnnotations.MaybeNull;
|
|
}
|
|
if (attributeData.HasNotNullAttribute)
|
|
{
|
|
flowAnalysisAnnotations |= FlowAnalysisAnnotations.NotNull;
|
|
}
|
|
}
|
|
return flowAnalysisAnnotations;
|
|
}
|
|
|
|
private bool IsVtableGapInterfaceMethod()
|
|
{
|
|
if (ContainingType.IsInterface)
|
|
{
|
|
return ModuleExtensions.GetVTableGapSize(MetadataName) > 0;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal override IEnumerable<SecurityAttribute> GetSecurityInformation()
|
|
{
|
|
CustomAttributesBag<CSharpAttributeData> attributesBag = GetAttributesBag();
|
|
MethodWellKnownAttributeData methodWellKnownAttributeData = (MethodWellKnownAttributeData)(object)attributesBag.DecodedWellKnownAttributeData;
|
|
if (methodWellKnownAttributeData != null)
|
|
{
|
|
SecurityWellKnownAttributeData securityInformation = ((CommonMethodWellKnownAttributeData)methodWellKnownAttributeData).SecurityInformation;
|
|
if (securityInformation != null)
|
|
{
|
|
return securityInformation.GetSecurityAttributes<CSharpAttributeData>(attributesBag.Attributes);
|
|
}
|
|
}
|
|
return SpecializedCollections.EmptyEnumerable<SecurityAttribute>();
|
|
}
|
|
|
|
public override DllImportData? GetDllImportData()
|
|
{
|
|
MethodWellKnownAttributeData decodedWellKnownAttributeData = GetDecodedWellKnownAttributeData();
|
|
if (decodedWellKnownAttributeData == null)
|
|
{
|
|
return null;
|
|
}
|
|
return ((CommonMethodWellKnownAttributeData)decodedWellKnownAttributeData).DllImportPlatformInvokeData;
|
|
}
|
|
}
|