Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors INullCoalescingExpression to ICoalesce expression, and prop… #21458

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,15 @@ private IConditionalChoiceExpression CreateBoundConditionalOperatorOperation(Bou
return new LazyConditionalChoiceExpression(condition, ifTrueValue, ifFalseValue, _semanticModel, syntax, type, constantValue, isImplicit);
}

private INullCoalescingExpression CreateBoundNullCoalescingOperatorOperation(BoundNullCoalescingOperator boundNullCoalescingOperator)
private ICoalesceExpression CreateBoundNullCoalescingOperatorOperation(BoundNullCoalescingOperator boundNullCoalescingOperator)
{
Lazy<IOperation> primaryOperand = new Lazy<IOperation>(() => Create(boundNullCoalescingOperator.LeftOperand));
Lazy<IOperation> secondaryOperand = new Lazy<IOperation>(() => Create(boundNullCoalescingOperator.RightOperand));
Lazy<IOperation> expression = new Lazy<IOperation>(() => Create(boundNullCoalescingOperator.LeftOperand));
Lazy<IOperation> whenNull = new Lazy<IOperation>(() => Create(boundNullCoalescingOperator.RightOperand));
SyntaxNode syntax = boundNullCoalescingOperator.Syntax;
ITypeSymbol type = boundNullCoalescingOperator.Type;
Optional<object> constantValue = ConvertToOptional(boundNullCoalescingOperator.ConstantValue);
bool isImplicit = boundNullCoalescingOperator.WasCompilerGenerated;
return new LazyNullCoalescingExpression(primaryOperand, secondaryOperand, _semanticModel, syntax, type, constantValue, isImplicit);
return new LazyCoalesceExpression(expression, whenNull, _semanticModel, syntax, type, constantValue, isImplicit);
}

private IAwaitExpression CreateBoundAwaitExpressionOperation(BoundAwaitExpression boundAwaitExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ static void Main(string[] args)
IVariableDeclarationStatement (1 declarations) (OperationKind.VariableDeclarationStatement) (Syntax: 'object /*<b ... *</bind>*/;')
IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'object /*<b ... *</bind>*/;')
Variables: Local_1: System.Object o
Initializer: INullCoalescingExpression (OperationKind.NullCoalescingExpression, Type: System.Object) (Syntax: 'new object( ... Exception()')
Left: IObjectCreationExpression (Constructor: System.Object..ctor()) (OperationKind.ObjectCreationExpression, Type: System.Object) (Syntax: 'new object()')
Initializer: ICoalesceExpression (OperationKind.CoalesceExpression, Type: System.Object) (Syntax: 'new object( ... Exception()')
Expression: IObjectCreationExpression (Constructor: System.Object..ctor()) (OperationKind.ObjectCreationExpression, Type: System.Object) (Syntax: 'new object()')
Arguments(0)
Initializer: null
Right: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'throw new Exception()')
WhenNull: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'throw new Exception()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand: IThrowExpression (OperationKind.ThrowExpression, Type: null) (Syntax: 'throw new Exception()')
IObjectCreationExpression (Constructor: System.Exception..ctor()) (OperationKind.ObjectCreationExpression, Type: System.Exception) (Syntax: 'new Exception()')
Expand All @@ -342,7 +342,7 @@ static void Main(string[] args)
OperationSelector = (operation) =>
{
var initializer = ((IVariableDeclarationStatement)operation).Declarations.Single().Initializer;
return (IConversionExpression)((INullCoalescingExpression)initializer).SecondaryOperand;
return (IConversionExpression)((ICoalesceExpression)initializer).WhenNull;
}
}.Verify);
}
Expand Down
52 changes: 26 additions & 26 deletions src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3039,74 +3039,74 @@ public LazyMethodBindingExpression(IMethodSymbol method, bool isVirtual, Lazy<IO
/// <summary>
/// Represents a null-coalescing expression.
/// </summary>
internal abstract partial class BaseNullCoalescingExpression : Operation, INullCoalescingExpression
internal abstract partial class BaseCoalesceExpression : Operation, ICoalesceExpression
{
protected BaseNullCoalescingExpression(SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(OperationKind.NullCoalescingExpression, semanticModel, syntax, type, constantValue, isImplicit)
protected BaseCoalesceExpression(SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(OperationKind.CoalesceExpression, semanticModel, syntax, type, constantValue, isImplicit)
{
}

protected abstract IOperation PrimaryOperandImpl { get; }
protected abstract IOperation SecondaryOperandImpl { get; }
protected abstract IOperation ExpressionImpl { get; }
protected abstract IOperation WhenNullImpl { get; }
public override IEnumerable<IOperation> Children
{
get
{
yield return PrimaryOperand;
yield return SecondaryOperand;
yield return Expression;
yield return WhenNull;
}
}
/// <summary>
/// Value to be unconditionally evaluated.
/// </summary>
public IOperation PrimaryOperand => Operation.SetParentOperation(PrimaryOperandImpl, this);
public IOperation Expression => Operation.SetParentOperation(ExpressionImpl, this);
/// <summary>
/// Value to be evaluated if Primary evaluates to null/Nothing.
/// Value to be evaluated if <see cref="Expression"/> evaluates to null/Nothing.
/// </summary>
public IOperation SecondaryOperand => Operation.SetParentOperation(SecondaryOperandImpl, this);
public IOperation WhenNull => Operation.SetParentOperation(WhenNullImpl, this);
public override void Accept(OperationVisitor visitor)
{
visitor.VisitNullCoalescingExpression(this);
visitor.VisitCoalesceExpression(this);
}
public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, TResult> visitor, TArgument argument)
{
return visitor.VisitNullCoalescingExpression(this, argument);
return visitor.VisitCoalesceExpression(this, argument);
}
}

/// <summary>
/// Represents a null-coalescing expression.
/// </summary>
internal sealed partial class NullCoalescingExpression : BaseNullCoalescingExpression, INullCoalescingExpression
internal sealed partial class CoalesceExpression : BaseCoalesceExpression, ICoalesceExpression
{
public NullCoalescingExpression(IOperation primaryOperand, IOperation secondaryOperand, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
public CoalesceExpression(IOperation expression, IOperation whenNull, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(semanticModel, syntax, type, constantValue, isImplicit)
{
PrimaryOperandImpl = primaryOperand;
SecondaryOperandImpl = secondaryOperand;
ExpressionImpl = expression;
WhenNullImpl = whenNull;
}

protected override IOperation PrimaryOperandImpl { get; }
protected override IOperation SecondaryOperandImpl { get; }
protected override IOperation ExpressionImpl { get; }
protected override IOperation WhenNullImpl { get; }
}

/// <summary>
/// Represents a null-coalescing expression.
/// </summary>
internal sealed partial class LazyNullCoalescingExpression : BaseNullCoalescingExpression, INullCoalescingExpression
internal sealed partial class LazyCoalesceExpression : BaseCoalesceExpression, ICoalesceExpression
{
private readonly Lazy<IOperation> _lazyPrimaryOperand;
private readonly Lazy<IOperation> _lazySecondaryOperand;
private readonly Lazy<IOperation> _lazyExpression;
private readonly Lazy<IOperation> _lazyWhenNull;

public LazyNullCoalescingExpression(Lazy<IOperation> primaryOperand, Lazy<IOperation> secondaryOperand, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) : base(semanticModel, syntax, type, constantValue, isImplicit)
public LazyCoalesceExpression(Lazy<IOperation> expression, Lazy<IOperation> whenNull, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) : base(semanticModel, syntax, type, constantValue, isImplicit)
{
_lazyPrimaryOperand = primaryOperand ?? throw new System.ArgumentNullException(nameof(primaryOperand));
_lazySecondaryOperand = secondaryOperand ?? throw new System.ArgumentNullException(nameof(secondaryOperand));
_lazyExpression = expression ?? throw new System.ArgumentNullException(nameof(expression));
_lazyWhenNull = whenNull ?? throw new System.ArgumentNullException(nameof(whenNull));
}

protected override IOperation PrimaryOperandImpl => _lazyPrimaryOperand.Value;
protected override IOperation ExpressionImpl => _lazyExpression.Value;

protected override IOperation SecondaryOperandImpl => _lazySecondaryOperand.Value;
protected override IOperation WhenNullImpl => _lazyWhenNull.Value;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ namespace Microsoft.CodeAnalysis.Semantics
/// This interface is reserved for implementation by its associated APIs. We reserve the right to
/// change it in the future.
/// </remarks>
public interface INullCoalescingExpression : IOperation
public interface ICoalesceExpression : IOperation
{
/// <summary>
/// Value to be unconditionally evaluated.
/// </summary>
IOperation PrimaryOperand { get; }
IOperation Expression { get; }
/// <summary>
/// Value to be evaluated if Primary evaluates to null/Nothing.
/// Value to be evaluated if <see cref="Expression"/> evaluates to null/Nothing.
/// </summary>
IOperation SecondaryOperand { get; }
IOperation WhenNull { get; }
}
}

4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/Operations/OperationCloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ public override IOperation VisitConditionalChoiceExpression(IConditionalChoiceEx
return new ConditionalChoiceExpression(Visit(operation.Condition), Visit(operation.IfTrueValue), Visit(operation.IfFalseValue), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
}

public override IOperation VisitNullCoalescingExpression(INullCoalescingExpression operation, object argument)
public override IOperation VisitCoalesceExpression(ICoalesceExpression operation, object argument)
{
return new NullCoalescingExpression(Visit(operation.PrimaryOperand), Visit(operation.SecondaryOperand), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
return new CoalesceExpression(Visit(operation.Expression), Visit(operation.WhenNull), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
}

public override IOperation VisitIsTypeExpression(IIsTypeExpression operation, object argument)
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/Operations/OperationKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public enum OperationKind
BinaryOperatorExpression = 0x10e,
/// <summary>Indicates an <see cref="IConditionalChoiceExpression"/>.</summary>
ConditionalChoiceExpression = 0x10f,
/// <summary>Indicates an <see cref="INullCoalescingExpression"/>.</summary>
NullCoalescingExpression = 0x110,
/// <summary>Indicates an <see cref="ICoalesceExpression"/>.</summary>
CoalesceExpression = 0x110,
/// <summary>Indicates an <see cref="ILambdaExpression"/>.</summary>
LambdaExpression = 0x111,
/// <summary>Indicates an <see cref="IObjectCreationExpression"/>.</summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/Operations/OperationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public virtual void VisitConditionalChoiceExpression(IConditionalChoiceExpressio
DefaultVisit(operation);
}

public virtual void VisitNullCoalescingExpression(INullCoalescingExpression operation)
public virtual void VisitCoalesceExpression(ICoalesceExpression operation)
{
DefaultVisit(operation);
}
Expand Down Expand Up @@ -740,7 +740,7 @@ public virtual TResult VisitConditionalChoiceExpression(IConditionalChoiceExpres
return DefaultVisit(operation, argument);
}

public virtual TResult VisitNullCoalescingExpression(INullCoalescingExpression operation, TArgument argument)
public virtual TResult VisitCoalesceExpression(ICoalesceExpression operation, TArgument argument)
{
return DefaultVisit(operation, argument);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Microsoft.CodeAnalysis.OperationKind.MemberInitializerExpression = 289 -> Micros
Microsoft.CodeAnalysis.OperationKind.MethodBindingExpression = 265 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.NameOfExpression = 291 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.None = 0 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.NullCoalescingExpression = 272 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.CoalesceExpression = 272 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.ObjectCreationExpression = 274 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.ObjectOrCollectionInitializerExpression = 288 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.OmittedArgumentExpression = 768 -> Microsoft.CodeAnalysis.OperationKind
Expand Down Expand Up @@ -512,9 +512,9 @@ Microsoft.CodeAnalysis.Semantics.IMethodBindingExpression.IsVirtual.get -> bool
Microsoft.CodeAnalysis.Semantics.IMethodBindingExpression.Method.get -> Microsoft.CodeAnalysis.IMethodSymbol
Microsoft.CodeAnalysis.Semantics.INameOfExpression
Microsoft.CodeAnalysis.Semantics.INameOfExpression.Argument.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.Semantics.INullCoalescingExpression
Microsoft.CodeAnalysis.Semantics.INullCoalescingExpression.PrimaryOperand.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.Semantics.INullCoalescingExpression.SecondaryOperand.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.Semantics.ICoalesceExpression
Microsoft.CodeAnalysis.Semantics.ICoalesceExpression.Expression.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.Semantics.ICoalesceExpression.WhenNull.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.Semantics.IObjectCreationExpression
Microsoft.CodeAnalysis.Semantics.IObjectCreationExpression.Constructor.get -> Microsoft.CodeAnalysis.IMethodSymbol
Microsoft.CodeAnalysis.Semantics.IObjectCreationExpression.Initializer.get -> Microsoft.CodeAnalysis.Semantics.IObjectOrCollectionInitializerExpression
Expand Down Expand Up @@ -828,7 +828,7 @@ virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLockStatement(Mic
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitMemberInitializerExpression(Microsoft.CodeAnalysis.Semantics.IMemberInitializerExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitMethodBindingExpression(Microsoft.CodeAnalysis.Semantics.IMethodBindingExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitNameOfExpression(Microsoft.CodeAnalysis.Semantics.INameOfExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitNullCoalescingExpression(Microsoft.CodeAnalysis.Semantics.INullCoalescingExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitCoalesceExpression(Microsoft.CodeAnalysis.Semantics.ICoalesceExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitObjectCreationExpression(Microsoft.CodeAnalysis.Semantics.IObjectCreationExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitObjectOrCollectionInitializerExpression(Microsoft.CodeAnalysis.Semantics.IObjectOrCollectionInitializerExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitOmittedArgumentExpression(Microsoft.CodeAnalysis.Semantics.IOmittedArgumentExpression operation) -> void
Expand Down Expand Up @@ -918,7 +918,7 @@ virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.Vi
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitMemberInitializerExpression(Microsoft.CodeAnalysis.Semantics.IMemberInitializerExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitMethodBindingExpression(Microsoft.CodeAnalysis.Semantics.IMethodBindingExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitNameOfExpression(Microsoft.CodeAnalysis.Semantics.INameOfExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitNullCoalescingExpression(Microsoft.CodeAnalysis.Semantics.INullCoalescingExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitCoalesceExpression(Microsoft.CodeAnalysis.Semantics.ICoalesceExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitObjectCreationExpression(Microsoft.CodeAnalysis.Semantics.IObjectCreationExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitObjectOrCollectionInitializerExpression(Microsoft.CodeAnalysis.Semantics.IObjectOrCollectionInitializerExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitOmittedArgumentExpression(Microsoft.CodeAnalysis.Semantics.IOmittedArgumentExpression operation, TArgument argument) -> TResult
Expand Down
Loading