36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using System.Diagnostics;
|
|||
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
||
|
|
|
||
|
|
internal sealed class BoundConstantPattern : BoundPattern
|
||
|
|
{
|
||
|
|
public BoundExpression Value { get; }
|
||
|
|
|
||
|
|
public ConstantValue ConstantValue { get; }
|
||
|
|
|
||
|
|
public BoundConstantPattern(SyntaxNode syntax, BoundExpression value, ConstantValue constantValue, TypeSymbol inputType, TypeSymbol narrowedType, bool hasErrors = false)
|
||
|
|
: base(BoundKind.ConstantPattern, syntax, inputType, narrowedType, hasErrors || value.HasErrors())
|
||
|
|
{
|
||
|
|
Value = value;
|
||
|
|
ConstantValue = constantValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
[DebuggerStepThrough]
|
||
|
|
public override BoundNode? Accept(BoundTreeVisitor visitor)
|
||
|
|
{
|
||
|
|
return visitor.VisitConstantPattern(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public BoundConstantPattern Update(BoundExpression value, ConstantValue constantValue, TypeSymbol inputType, TypeSymbol narrowedType)
|
||
|
|
{
|
||
|
|
if (value != Value || constantValue != ConstantValue || !TypeSymbol.Equals(inputType, base.InputType, (TypeCompareKind)0) || !TypeSymbol.Equals(narrowedType, base.NarrowedType, (TypeCompareKind)0))
|
||
|
|
{
|
||
|
|
BoundConstantPattern boundConstantPattern = new BoundConstantPattern(Syntax, value, constantValue, inputType, narrowedType, base.HasErrors);
|
||
|
|
boundConstantPattern.CopyAttributes(this);
|
||
|
|
return boundConstantPattern;
|
||
|
|
}
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
}
|