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

refactored IAssignment/ICompoundAssignment as we discussed and removed IndexPropertyReference #20431

Merged
merged 16 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -266,15 +266,16 @@ private IPropertyReferenceExpression CreateBoundPropertyAccessOperation(BoundPro
{
IPropertySymbol property = boundPropertyAccess.PropertySymbol;
Lazy<IOperation> instance = new Lazy<IOperation>(() => Create(boundPropertyAccess.PropertySymbol.IsStatic ? null : boundPropertyAccess.ReceiverOpt));
Lazy<ImmutableArray<IArgument>> argumentsInEvaluationOrder = new Lazy<ImmutableArray<IArgument>>(() => ImmutableArray<IArgument>.Empty);
ISymbol member = boundPropertyAccess.PropertySymbol;
bool isInvalid = boundPropertyAccess.HasErrors;
SyntaxNode syntax = boundPropertyAccess.Syntax;
ITypeSymbol type = boundPropertyAccess.Type;
Optional<object> constantValue = ConvertToOptional(boundPropertyAccess.ConstantValue);
return new LazyPropertyReferenceExpression(property, instance, member, isInvalid, syntax, type, constantValue);
return new LazyPropertyReferenceExpression(property, instance, member, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue);
}

private IIndexedPropertyReferenceExpression CreateBoundIndexerAccessOperation(BoundIndexerAccess boundIndexerAccess)
private IPropertyReferenceExpression CreateBoundIndexerAccessOperation(BoundIndexerAccess boundIndexerAccess)
{
IPropertySymbol property = boundIndexerAccess.Indexer;
Lazy<IOperation> instance = new Lazy<IOperation>(() => Create(boundIndexerAccess.Indexer.IsStatic ? null : boundIndexerAccess.ReceiverOpt));
Expand Down Expand Up @@ -303,7 +304,7 @@ private IIndexedPropertyReferenceExpression CreateBoundIndexerAccessOperation(Bo
SyntaxNode syntax = boundIndexerAccess.Syntax;
ITypeSymbol type = boundIndexerAccess.Type;
Optional<object> constantValue = ConvertToOptional(boundIndexerAccess.ConstantValue);
return new LazyIndexedPropertyReferenceExpression(property, instance, member, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue);
return new LazyPropertyReferenceExpression(property, instance, member, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue);
}

private IEventReferenceExpression CreateBoundEventAccessOperation(BoundEventAccess boundEventAccess)
Expand Down Expand Up @@ -536,15 +537,15 @@ private IInstanceReferenceExpression CreateBoundThisReferenceOperation(BoundThis
return new InstanceReferenceExpression(instanceReferenceKind, isInvalid, syntax, type, constantValue);
}

private IAssignmentExpression CreateBoundAssignmentOperatorOperation(BoundAssignmentOperator boundAssignmentOperator)
private ISimpleAssignmentExpression CreateBoundAssignmentOperatorOperation(BoundAssignmentOperator boundAssignmentOperator)
{
Lazy<IOperation> target = new Lazy<IOperation>(() => Create(boundAssignmentOperator.Left));
Lazy<IOperation> value = new Lazy<IOperation>(() => Create(boundAssignmentOperator.Right));
bool isInvalid = boundAssignmentOperator.HasErrors;
SyntaxNode syntax = boundAssignmentOperator.Syntax;
ITypeSymbol type = boundAssignmentOperator.Type;
Optional<object> constantValue = ConvertToOptional(boundAssignmentOperator.ConstantValue);
return new LazyAssignmentExpression(target, value, isInvalid, syntax, type, constantValue);
return new LazySimpleAssignmentExpression(target, value, isInvalid, syntax, type, constantValue);
}

private ICompoundAssignmentExpression CreateBoundCompoundAssignmentOperatorOperation(BoundCompoundAssignmentOperator boundCompoundAssignmentOperator)
Expand All @@ -564,16 +565,14 @@ private ICompoundAssignmentExpression CreateBoundCompoundAssignmentOperatorOpera
private IIncrementExpression CreateBoundIncrementOperatorOperation(BoundIncrementOperator boundIncrementOperator)
{
UnaryOperationKind incrementOperationKind = Helper.DeriveUnaryOperationKind(boundIncrementOperator.OperatorKind);
BinaryOperationKind binaryOperationKind = Helper.DeriveBinaryOperationKind(incrementOperationKind);
Lazy<IOperation> target = new Lazy<IOperation>(() => Create(boundIncrementOperator.Operand));
Lazy<IOperation> value = new Lazy<IOperation>(() => CreateIncrementOneLiteralExpression(boundIncrementOperator));
bool usesOperatorMethod = (boundIncrementOperator.OperatorKind & UnaryOperatorKind.TypeMask) == UnaryOperatorKind.UserDefined;
IMethodSymbol operatorMethod = boundIncrementOperator.MethodOpt;
bool isInvalid = boundIncrementOperator.HasErrors;
SyntaxNode syntax = boundIncrementOperator.Syntax;
ITypeSymbol type = boundIncrementOperator.Type;
Optional<object> constantValue = ConvertToOptional(boundIncrementOperator.ConstantValue);
return new LazyIncrementExpression(incrementOperationKind, binaryOperationKind, target, value, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue);
return new LazyIncrementExpression(incrementOperationKind, target, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue);
}

private IInvalidExpression CreateBoundBadExpressionOperation(BoundBadExpression boundBadExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ private ImmutableArray<IOperation> ToStatements(BoundStatement statement)
return ImmutableArray.Create(Create(statement));
}

private ILiteralExpression CreateIncrementOneLiteralExpression(BoundIncrementOperator increment)
{
string text = increment.Syntax.ToString();
bool isInvalid = false;
SyntaxNode syntax = increment.Syntax;
ITypeSymbol type = increment.Type;
Optional<object> constantValue = ConvertToOptional(Semantics.Expression.SynthesizeNumeric(increment.Type, 1));
return new LiteralExpression(text, isInvalid, syntax, type, constantValue);
}

internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterSymbol parameter, IOperation value)
{
return new Argument(kind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ public void Deconstruct(out int a, out int b, out int c)
IOperation operation1 = model.GetOperation(assignments[0]);
Assert.NotNull(operation1);
Assert.Equal(OperationKind.None, operation1.Kind);
Assert.False(operation1 is IAssignmentExpression);
Assert.False(operation1 is ISimpleAssignmentExpression);

Assert.Equal("(x, y, z) = new C()", assignments[1].ToString());
IOperation operation2 = model.GetOperation(assignments[1]);
Assert.NotNull(operation2);
Assert.Equal(OperationKind.None, operation2.Kind);
Assert.False(operation2 is IAssignmentExpression);
Assert.False(operation2 is ISimpleAssignmentExpression);

Assert.Equal("var (a, b) = (1, 2)", assignments[2].ToString());
IOperation operation3 = model.GetOperation(assignments[2]);
Assert.NotNull(operation3);
Assert.Equal(OperationKind.None, operation3.Kind);
Assert.False(operation3 is IAssignmentExpression);
Assert.False(operation3 is ISimpleAssignmentExpression);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Semantics;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand Down Expand Up @@ -1079,7 +1079,7 @@ void M1()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[10]')
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Explicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: index) (OperationKind.Argument) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')
Expand Down Expand Up @@ -1109,7 +1109,7 @@ void M1()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[10]')
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Explicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: index) (OperationKind.Argument) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')
Expand Down Expand Up @@ -1139,7 +1139,7 @@ void M1()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 1], [System.Int32 j = 2]] { get; set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[j:10]')
IPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 1], [System.Int32 j = 2]] { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[j:10]')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Explicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(2): IArgument (ArgumentKind.Explicit, Matching Parameter: j) (OperationKind.Argument) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')
Expand Down Expand Up @@ -1171,7 +1171,7 @@ void M1()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Explicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: null) (OperationKind.Argument, IsInvalid) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')";
Expand Down Expand Up @@ -1203,7 +1203,7 @@ void M1()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; } (OperationKind.PropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Explicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: null) (OperationKind.Argument, IsInvalid) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')
Expand Down Expand Up @@ -1249,7 +1249,7 @@ static void Main()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 Derived.this[[System.Int32 x = 8], [System.Int32 y = 9]] { set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'd[0]')
IPropertyReferenceExpression: System.Int32 Derived.this[[System.Int32 x = 8], [System.Int32 y = 9]] { set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'd[0]')
Instance Receiver: ILocalReferenceExpression: d (OperationKind.LocalReferenceExpression, Type: Derived) (Syntax: 'd')
Arguments(2): IArgument (ArgumentKind.Explicit, Matching Parameter: x) (OperationKind.Argument) (Syntax: '0')
ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')
Expand All @@ -1260,7 +1260,7 @@ static void Main()

string expectedOutput = @"1";

VerifyOperationTreeAndDiagnosticsForTest<ElementAccessExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics, AdditionalOperationTreeVerifier: IndexerAccessArgumentVerifier.Verify);
VerifyOperationTreeAndDiagnosticsForTest<ElementAccessExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics, AdditionalOperationTreeVerifier: IndexerAccessArgumentVerifier.Verify);

CompileAndVerify(new[] { source }, new[] { SystemRef }, expectedOutput: expectedOutput);
}
Expand All @@ -1284,7 +1284,7 @@ public void M()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[System.Int32 x, params System.Int32[] y] { get; set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[0]')
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 x, params System.Int32[] y] { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[0]')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Explicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(2): IArgument (ArgumentKind.Explicit, Matching Parameter: x) (OperationKind.Argument) (Syntax: '0')
ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')
Expand Down Expand Up @@ -1316,15 +1316,15 @@ public void M()
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: ref System.Int32 P.this[System.Int32 x] { get; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[0]')
IPropertyReferenceExpression: ref System.Int32 P.this[System.Int32 x] { get; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'this[0]')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Explicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: x) (OperationKind.Argument) (Syntax: '0')
ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')
";
var expectedDiagnostics = DiagnosticDescription.None;

VerifyOperationTreeAndDiagnosticsForTest<ElementAccessExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics, AdditionalOperationTreeVerifier: IndexerAccessArgumentVerifier.Verify);
}
}

[ClrOnlyFact(ClrOnlyReason.Ilasm)]
public void AssigningToIndexer_UsingDefaultArgumentFromSetter()
Expand Down Expand Up @@ -1408,7 +1408,7 @@ .property instance int32 Item(int32,
int32)
} // end of property P::Item
} // end of class P
";
";

var csharp = @"
class C
Expand All @@ -1421,7 +1421,7 @@ public static void Main(string[] args)
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 3], [System.Int32 j = 4]] { get; set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'p[10]')
IPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 3], [System.Int32 j = 4]] { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'p[10]')
Instance Receiver: ILocalReferenceExpression: p (OperationKind.LocalReferenceExpression, Type: P) (Syntax: 'p')
Arguments(2): IArgument (ArgumentKind.Explicit, Matching Parameter: i) (OperationKind.Argument) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')
Expand Down Expand Up @@ -1531,7 +1531,7 @@ public static void Main(string[] args)
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 3], [System.Int32 j = 4]] { get; set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'p[10]')
IPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 3], [System.Int32 j = 4]] { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'p[10]')
Instance Receiver: ILocalReferenceExpression: p (OperationKind.LocalReferenceExpression, Type: P) (Syntax: 'p')
Arguments(2): IArgument (ArgumentKind.Explicit, Matching Parameter: i) (OperationKind.Argument) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')
Expand Down Expand Up @@ -1643,7 +1643,7 @@ public static void Main(string[] args)
}
";
string expectedOperationTree = @"
IIndexedPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 3], [System.Int32 j = 4]] { get; set; } (OperationKind.IndexedPropertyReferenceExpression, Type: System.Int32) (Syntax: 'p[10]')
IPropertyReferenceExpression: System.Int32 P.this[[System.Int32 i = 3], [System.Int32 j = 4]] { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'p[10]')
Instance Receiver: ILocalReferenceExpression: p (OperationKind.LocalReferenceExpression, Type: P) (Syntax: 'p')
Arguments(2): IArgument (ArgumentKind.Explicit, Matching Parameter: i) (OperationKind.Argument) (Syntax: '10')
ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10')
Expand Down Expand Up @@ -1724,9 +1724,9 @@ public static void Verify(IOperation operation, Compilation compilationIgnored,
Instance.Visit(operation);
}

public override void VisitIndexedPropertyReferenceExpression(IIndexedPropertyReferenceExpression operation)
public override void VisitPropertyReferenceExpression(IPropertyReferenceExpression operation)
{
if (operation.IsInvalid)
if (operation.IsInvalid || operation.ArgumentsInEvaluationOrder.Length == 0)
{
return;
}
Expand All @@ -1742,5 +1742,5 @@ public override void VisitIndexedPropertyReferenceExpression(IIndexedPropertyRef
}
}
}
}
}
}
Loading