Skip to content

Commit

Permalink
Refactors INullCoalescingExpression to ICoalesce expression, and prop…
Browse files Browse the repository at this point in the history
…erties to sensible names.
  • Loading branch information
333fred committed Aug 11, 2017
1 parent c7054db commit 68bb957
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,14 @@ private IConditionalChoiceExpression CreateBoundConditionalOperatorOperation(Bou
return new LazyConditionalChoiceExpression(condition, ifTrueValue, ifFalseValue, _semanticModel, syntax, type, constantValue);
}

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);
return new LazyNullCoalescingExpression(primaryOperand, secondaryOperand, _semanticModel, syntax, type, constantValue);
return new LazyCoalesceExpression(expression, whenNull, _semanticModel, syntax, type, constantValue);
}

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) :
base(OperationKind.NullCoalescingExpression, semanticModel, syntax, type, constantValue)
protected BaseCoalesceExpression(SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) :
base(OperationKind.CoalesceExpression, semanticModel, syntax, type, constantValue)
{
}

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) :
public CoalesceExpression(IOperation expression, IOperation whenNull, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) :
base(semanticModel, syntax, type, constantValue)
{
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) : base(semanticModel, syntax, type, constantValue)
public LazyCoalesceExpression(Lazy<IOperation> expression, Lazy<IOperation> whenNull, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) : base(semanticModel, syntax, type, constantValue)
{
_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);
}

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);
return new CoalesceExpression(Visit(operation.Expression), Visit(operation.WhenNull), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue);
}

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 @@ -827,7 +827,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 @@ -917,7 +917,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

0 comments on commit 68bb957

Please sign in to comment.