98 lines
4.1 KiB
C#
98 lines
4.1 KiB
C#
using System;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
|
|
|
internal sealed class EarlyWellKnownAttributeBinder : Binder
|
|
{
|
|
internal EarlyWellKnownAttributeBinder(Binder enclosing)
|
|
: base(enclosing, enclosing.Flags | BinderFlags.EarlyAttributeBinding)
|
|
{
|
|
}
|
|
|
|
internal (CSharpAttributeData, BoundAttribute) GetAttribute(AttributeSyntax node, NamedTypeSymbol boundAttributeType, Action<AttributeSyntax> beforeAttributePartBound, Action<AttributeSyntax> afterAttributePartBound, out bool generatedDiagnostics)
|
|
{
|
|
BindingDiagnosticBag instance = BindingDiagnosticBag.GetInstance(withDiagnostics: true, withDependencies: false);
|
|
(CSharpAttributeData, BoundAttribute) attribute = base.GetAttribute(node, boundAttributeType, beforeAttributePartBound, afterAttributePartBound, instance);
|
|
generatedDiagnostics = !((BindingDiagnosticBag)instance).DiagnosticBag.IsEmptyWithoutResolution;
|
|
((BindingDiagnosticBag<AssemblySymbol>)(object)instance).Free();
|
|
return attribute;
|
|
}
|
|
|
|
[Obsolete("EarlyWellKnownAttributeBinder has a better overload - GetAttribute(AttributeSyntax, NamedTypeSymbol, out bool)", true)]
|
|
internal new (CSharpAttributeData, BoundAttribute) GetAttribute(AttributeSyntax node, NamedTypeSymbol boundAttributeType, Action<AttributeSyntax> beforeAttributePartBound, Action<AttributeSyntax> afterAttributePartBound, BindingDiagnosticBag diagnostics)
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_InternalError, ((SyntaxNode)node).Location);
|
|
return base.GetAttribute(node, boundAttributeType, beforeAttributePartBound, afterAttributePartBound, diagnostics);
|
|
}
|
|
|
|
internal static bool CanBeValidAttributeArgument(ExpressionSyntax node)
|
|
{
|
|
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
|
|
switch (node.Kind())
|
|
{
|
|
case SyntaxKind.ObjectCreationExpression:
|
|
case SyntaxKind.ImplicitObjectCreationExpression:
|
|
{
|
|
BaseObjectCreationExpressionSyntax baseObjectCreationExpressionSyntax = (BaseObjectCreationExpressionSyntax)node;
|
|
if (baseObjectCreationExpressionSyntax.Initializer == null)
|
|
{
|
|
return (baseObjectCreationExpressionSyntax.ArgumentList?.Arguments.Count ?? 0) == 0;
|
|
}
|
|
return false;
|
|
}
|
|
case SyntaxKind.IdentifierName:
|
|
case SyntaxKind.QualifiedName:
|
|
case SyntaxKind.GenericName:
|
|
case SyntaxKind.AliasQualifiedName:
|
|
case SyntaxKind.PredefinedType:
|
|
case SyntaxKind.ParenthesizedExpression:
|
|
case SyntaxKind.ConditionalExpression:
|
|
case SyntaxKind.InvocationExpression:
|
|
case SyntaxKind.CastExpression:
|
|
case SyntaxKind.InterpolatedStringExpression:
|
|
case SyntaxKind.AddExpression:
|
|
case SyntaxKind.SubtractExpression:
|
|
case SyntaxKind.MultiplyExpression:
|
|
case SyntaxKind.DivideExpression:
|
|
case SyntaxKind.ModuloExpression:
|
|
case SyntaxKind.LeftShiftExpression:
|
|
case SyntaxKind.RightShiftExpression:
|
|
case SyntaxKind.LogicalOrExpression:
|
|
case SyntaxKind.LogicalAndExpression:
|
|
case SyntaxKind.BitwiseOrExpression:
|
|
case SyntaxKind.BitwiseAndExpression:
|
|
case SyntaxKind.ExclusiveOrExpression:
|
|
case SyntaxKind.EqualsExpression:
|
|
case SyntaxKind.NotEqualsExpression:
|
|
case SyntaxKind.LessThanExpression:
|
|
case SyntaxKind.LessThanOrEqualExpression:
|
|
case SyntaxKind.GreaterThanExpression:
|
|
case SyntaxKind.GreaterThanOrEqualExpression:
|
|
case SyntaxKind.SimpleMemberAccessExpression:
|
|
case SyntaxKind.UnsignedRightShiftExpression:
|
|
case SyntaxKind.UnaryPlusExpression:
|
|
case SyntaxKind.UnaryMinusExpression:
|
|
case SyntaxKind.BitwiseNotExpression:
|
|
case SyntaxKind.LogicalNotExpression:
|
|
case SyntaxKind.NumericLiteralExpression:
|
|
case SyntaxKind.StringLiteralExpression:
|
|
case SyntaxKind.CharacterLiteralExpression:
|
|
case SyntaxKind.TrueLiteralExpression:
|
|
case SyntaxKind.FalseLiteralExpression:
|
|
case SyntaxKind.NullLiteralExpression:
|
|
case SyntaxKind.Utf8StringLiteralExpression:
|
|
case SyntaxKind.TypeOfExpression:
|
|
case SyntaxKind.SizeOfExpression:
|
|
case SyntaxKind.CheckedExpression:
|
|
case SyntaxKind.UncheckedExpression:
|
|
case SyntaxKind.DefaultExpression:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
}
|