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

Add IOperation support for tuple expressions #20749

Merged
merged 10 commits into from
Jul 17, 2017
5 changes: 0 additions & 5 deletions src/Compilers/CSharp/Portable/BoundTree/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

namespace Microsoft.CodeAnalysis.CSharp
{
internal partial class BoundTupleExpression
{
protected override ImmutableArray<BoundNode> Children => StaticCast<BoundNode>.From(this.Arguments);
}

internal partial class BoundDelegateCreationExpression
{
protected override ImmutableArray<BoundNode> Children => ImmutableArray.Create<BoundNode>(this.Argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ private IOperation CreateInternal(BoundNode boundNode)
return CreateBoundLabeledStatementOperation((BoundLabeledStatement)boundNode);
case BoundKind.ExpressionStatement:
return CreateBoundExpressionStatementOperation((BoundExpressionStatement)boundNode);
case BoundKind.TupleLiteral:
case BoundKind.ConvertedTupleLiteral:
return CreateBoundTupleExpressionOperation((BoundTupleExpression)boundNode);
case BoundKind.InterpolatedString:
return CreateBoundInterpolatedStringExpressionOperation((BoundInterpolatedString)boundNode);
case BoundKind.StringInsert:
Expand Down Expand Up @@ -1189,6 +1192,15 @@ private IExpressionStatement CreateBoundExpressionStatementOperation(BoundExpres
return new LazyExpressionStatement(expression, syntax, type, constantValue);
}

private ITupleExpression CreateBoundTupleExpressionOperation(BoundTupleExpression boundTupleExpression)
{
Lazy<ImmutableArray<IOperation>> elements = new Lazy<ImmutableArray<IOperation>>(() => boundTupleExpression.Arguments.SelectAsArray(element => Create(element)));
SyntaxNode syntax = boundTupleExpression.Syntax;
ITypeSymbol type = boundTupleExpression.Type;
Optional<object> constantValue = default(Optional<object>);
return new LazyTupleExpression(elements, syntax, type, constantValue);
}

private IInterpolatedStringExpression CreateBoundInterpolatedStringExpressionOperation(BoundInterpolatedString boundInterpolatedString)
{
Lazy<ImmutableArray<IInterpolatedStringContent>> parts = new Lazy<ImmutableArray<IInterpolatedStringContent>>(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public void M(int x, int y)
}
";
string expectedOperationTree = @"
IOperation: (OperationKind.None) (Syntax: '(x, x + y)')
Children(2):
ITupleExpression (OperationKind.TupleExpression, Type: (System.Int32 x, System.Int32)) (Syntax: '(x, x + y)')
Elements(2):
IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'x')
IBinaryOperatorExpression (BinaryOperationKind.IntegerAdd) (OperationKind.BinaryOperatorExpression, Type: System.Int32) (Syntax: 'x + y')
Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'x')
Expand Down Expand Up @@ -72,8 +72,8 @@ public void M(Point point)
string expectedOperationTree = @"
IOperation: (OperationKind.None) (Syntax: 'var (x, y) = point')
Children(2):
IOperation: (OperationKind.None) (Syntax: 'var (x, y)')
Children(2):
ITupleExpression (OperationKind.TupleExpression, Type: (System.Int32 x, System.Int32 y)) (Syntax: 'var (x, y)')
Elements(2):
ILocalReferenceExpression: x (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'x')
ILocalReferenceExpression: y (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'y')
IConversionExpression (ConversionKind.Invalid, Implicit) (OperationKind.ConversionExpression, Type: (System.Int32 x, System.Int32 y)) (Syntax: 'point')
Expand Down
Loading