提交 d290266e 编写于 作者: M Manish Vasani

Changes as per the design team decision:

1) Use IDynamicInvocationExpression for VB late bound invocation and C# dynamic invocation.
2) Use IDynamicIndexerAccessExpression for C# dynamic indexer access; not used in VB.
3) Remove IDynamicObjectCreationExpression.MemberName property.
4) Add extension methods on IHasDynamicArgumentExpression to get optional argument name and ref kind for an argument at a given index.
上级 dd969b6a
......@@ -500,7 +500,6 @@ private IObjectCreationExpression CreateBoundObjectCreationExpressionOperation(B
private IDynamicObjectCreationExpression CreateBoundDynamicObjectCreationExpressionOperation(BoundDynamicObjectCreationExpression boundDynamicObjectCreationExpression)
{
string name = boundDynamicObjectCreationExpression.Name;
ImmutableArray<ISymbol> applicableSymbols = StaticCast<ISymbol>.From(boundDynamicObjectCreationExpression.ApplicableMethods);
Lazy<ImmutableArray<IOperation>> arguments = new Lazy<ImmutableArray<IOperation>>(() => boundDynamicObjectCreationExpression.Arguments.SelectAsArray(n => Create(n)));
ImmutableArray<string> argumentNames = boundDynamicObjectCreationExpression.ArgumentNamesOpt.NullToEmpty();
......@@ -510,7 +509,7 @@ private IDynamicObjectCreationExpression CreateBoundDynamicObjectCreationExpress
ITypeSymbol type = boundDynamicObjectCreationExpression.Type;
Optional<object> constantValue = ConvertToOptional(boundDynamicObjectCreationExpression.ConstantValue);
bool isImplicit = boundDynamicObjectCreationExpression.WasCompilerGenerated;
return new LazyDynamicObjectCreationExpression(name, applicableSymbols, arguments, argumentNames, argumentRefKinds, initializer, _semanticModel, syntax, type, constantValue, isImplicit);
return new LazyDynamicObjectCreationExpression(applicableSymbols, arguments, argumentNames, argumentRefKinds, initializer, _semanticModel, syntax, type, constantValue, isImplicit);
}
private IDynamicInvocationExpression CreateBoundDynamicInvocationExpressionOperation(BoundDynamicInvocation boundDynamicInvocation)
......@@ -527,7 +526,7 @@ private IDynamicInvocationExpression CreateBoundDynamicInvocationExpressionOpera
return new LazyDynamicInvocationExpression(expression, applicableSymbols, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, constantValue, isImplicit);
}
private IDynamicPropertyReferenceExpression CreateBoundDynamicIndexerAccessExpressionOperation(BoundDynamicIndexerAccess boundDynamicIndexerAccess)
private IDynamicIndexerAccessExpression CreateBoundDynamicIndexerAccessExpressionOperation(BoundDynamicIndexerAccess boundDynamicIndexerAccess)
{
Lazy<IOperation> expression = new Lazy<IOperation>(() => Create(boundDynamicIndexerAccess.ReceiverOpt));
ImmutableArray<ISymbol> applicableSymbols = StaticCast<ISymbol>.From(boundDynamicIndexerAccess.ApplicableIndexers);
......@@ -538,7 +537,7 @@ private IDynamicPropertyReferenceExpression CreateBoundDynamicIndexerAccessExpre
ITypeSymbol type = boundDynamicIndexerAccess.Type;
Optional<object> constantValue = ConvertToOptional(boundDynamicIndexerAccess.ConstantValue);
bool isImplicit = boundDynamicIndexerAccess.WasCompilerGenerated;
return new LazyDynamicPropertyReferenceExpression(expression, applicableSymbols, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, constantValue, isImplicit);
return new LazyDynamicIndexerAccessExpression(expression, applicableSymbols, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, constantValue, isImplicit);
}
private IObjectOrCollectionInitializerExpression CreateBoundObjectInitializerExpressionOperation(BoundObjectInitializerExpression boundObjectInitializerExpression)
......
......@@ -2,7 +2,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
......@@ -11,7 +10,7 @@ public partial class IOperationTests : SemanticModelTestBase
{
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_DynamicArgument()
public void DynamicIndexerAccessExpression_DynamicArgument()
{
string source = @"
class C
......@@ -25,7 +24,7 @@ void M(C c, dynamic d)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c[d]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c[d]')
Expression: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(1):
Symbol: System.Int32 C.this[System.Int32 i] { get; }
......@@ -41,7 +40,7 @@ void M(C c, dynamic d)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_MultipleApplicableSymbols()
public void DynamicIndexerAccessExpression_MultipleApplicableSymbols()
{
string source = @"
class C
......@@ -57,7 +56,7 @@ void M(C c, dynamic d)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c[d]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c[d]')
Expression: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: System.Int32 C.this[System.Int32 i] { get; }
......@@ -74,7 +73,7 @@ void M(C c, dynamic d)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_MultipleArgumentsAndApplicableSymbols()
public void DynamicIndexerAccessExpression_MultipleArgumentsAndApplicableSymbols()
{
string source = @"
class C
......@@ -91,7 +90,7 @@ void M(C c, dynamic d)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c[d, ch]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c[d, ch]')
Expression: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: System.Int32 C.this[System.Int32 i, System.Char ch] { get; }
......@@ -109,7 +108,7 @@ void M(C c, dynamic d)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_ArgumentNames()
public void DynamicIndexerAccessExpression_ArgumentNames()
{
string source = @"
class C
......@@ -125,7 +124,7 @@ void M(C c, dynamic d, dynamic e)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c[i: d, ch: e]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c[i: d, ch: e]')
Expression: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: System.Int32 C.this[System.Int32 i, System.Char ch] { get; }
......@@ -145,7 +144,7 @@ void M(C c, dynamic d, dynamic e)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_ArgumentRefKinds()
public void DynamicIndexerAccessExpression_ArgumentRefKinds()
{
string source = @"
class C
......@@ -159,7 +158,7 @@ void M(C c, dynamic d, dynamic e)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c[i: d, ch: ref e]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c[i: d, ch: ref e]')
Expression: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(1):
Symbol: System.Int32 C.this[System.Int32 i, ref dynamic ch] { get; }
......@@ -184,7 +183,7 @@ void M(C c, dynamic d, dynamic e)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_WithDynamicReceiver()
public void DynamicIndexerAccessExpression_WithDynamicReceiver()
{
string source = @"
class C
......@@ -198,7 +197,7 @@ void M(dynamic d, int i)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'd[i]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'd[i]')
Expression: IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: dynamic) (Syntax: 'd')
ApplicableSymbols(0)
Arguments(1):
......@@ -213,7 +212,7 @@ void M(dynamic d, int i)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_WithDynamicMemberReceiver()
public void DynamicIndexerAccessExpression_WithDynamicMemberReceiver()
{
string source = @"
class C
......@@ -227,7 +226,7 @@ void M(dynamic c, int i)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c.M2[i]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c.M2[i]')
Expression: IDynamicMemberReferenceExpression (Member Name: ""M2"", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: dynamic) (Syntax: 'c.M2')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: dynamic) (Syntax: 'c')
......@@ -244,7 +243,7 @@ Type Arguments(0)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_WithDynamicTypedMemberReceiver()
public void DynamicIndexerAccessExpression_WithDynamicTypedMemberReceiver()
{
string source = @"
class C
......@@ -258,7 +257,7 @@ void M(dynamic c, int i)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c.M2[i]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c.M2[i]')
Expression: IDynamicMemberReferenceExpression (Member Name: ""M2"", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: dynamic) (Syntax: 'c.M2')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: dynamic) (Syntax: 'c')
......@@ -279,7 +278,7 @@ Type Arguments(0)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_AllFields()
public void DynamicIndexerAccessExpression_AllFields()
{
string source = @"
class C
......@@ -295,7 +294,7 @@ void M(C c, dynamic d)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'c[ref i, c: d]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'c[ref i, c: d]')
Expression: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: System.Int32 C.this[ref System.Int32 i, System.Char c] { get; }
......@@ -324,7 +323,7 @@ void M(C c, dynamic d)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_ErrorBadDynamicMethodArgLambda()
public void DynamicIndexerAccessExpression_ErrorBadDynamicMethodArgLambda()
{
string source = @"
using System;
......@@ -341,7 +340,7 @@ public void M(C c)
}
";
string expectedOperationTree = @"
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic, IsInvalid) (Syntax: 'c[delegate { }, y]')
IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic, IsInvalid) (Syntax: 'c[delegate { }, y]')
Expression: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(1):
Symbol: System.Int32 C.this[System.Action a, System.Action y] { get; }
......@@ -365,7 +364,7 @@ public void M(C c)
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void DynamicPropertyReference_OverloadResolutionFailure()
public void DynamicIndexerAccessExpression_OverloadResolutionFailure()
{
string source = @"
using System;
......
......@@ -27,7 +27,7 @@ void M(dynamic d)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d)')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d)')
ApplicableSymbols(1):
Symbol: C..ctor(System.Int32 i)
Arguments(1):
......@@ -63,7 +63,7 @@ void M(dynamic d)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d)')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d)')
ApplicableSymbols(2):
Symbol: C..ctor(System.Int32 i)
Symbol: C..ctor(System.Int64 i)
......@@ -101,7 +101,7 @@ void M(dynamic d)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d, c)')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d, c)')
ApplicableSymbols(2):
Symbol: C..ctor(System.Int32 i, System.Char c)
Symbol: C..ctor(System.Int64 i, System.Char c)
......@@ -139,7 +139,7 @@ void M(dynamic d, dynamic e)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(i: d, c: e)')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(i: d, c: e)')
ApplicableSymbols(2):
Symbol: C..ctor(System.Int32 i, System.Char c)
Symbol: C..ctor(System.Int64 i, System.Char c)
......@@ -177,7 +177,7 @@ void M(object d, dynamic e)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(ref d, out k, e)')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(ref d, out k, e)')
ApplicableSymbols(1):
Symbol: C..ctor(ref System.Object i, out System.Int32 j, System.Char c)
Arguments(3):
......@@ -216,7 +216,7 @@ void M(dynamic d)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d) { X = 0 }')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(d) { X = 0 }')
ApplicableSymbols(1):
Symbol: C..ctor(System.Char c)
Arguments(1):
......@@ -260,7 +260,7 @@ void M(dynamic d)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(ref i ... ) { X = 0 }')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C) (Syntax: 'new C(ref i ... ) { X = 0 }')
ApplicableSymbols(2):
Symbol: C..ctor(ref System.Int32 i, System.Char c)
Symbol: C..ctor(ref System.Int32 i, System.Int64 c)
......@@ -306,7 +306,7 @@ public C(Action a, Action y)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: C) (OperationKind.DynamicObjectCreationExpression, Type: C, IsInvalid) (Syntax: 'new C(delegate { }, y)')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: C, IsInvalid) (Syntax: 'new C(delegate { }, y)')
ApplicableSymbols(1):
Symbol: C..ctor(System.Action a, System.Action y)
Arguments(2):
......
......@@ -543,7 +543,7 @@ public void M(dynamic d, int x)
IVariableDeclarationStatement (1 declarations) (OperationKind.VariableDeclarationStatement) (Syntax: 'var y /*<bi ... *</bind>*/;')
IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'var y /*<bi ... *</bind>*/;')
Variables: Local_1: dynamic y
Initializer: IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: dynamic) (Syntax: 'd[x]')
Initializer: IDynamicIndexerAccessExpression (OperationKind.DynamicIndexerAccessExpression, Type: dynamic) (Syntax: 'd[x]')
Expression: IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: dynamic) (Syntax: 'd')
ApplicableSymbols(0)
Arguments(1):
......@@ -629,7 +629,7 @@ public void M(dynamic x)
}
";
string expectedOperationTree = @"
IDynamicObjectCreationExpression (Name: Class) (OperationKind.DynamicObjectCreationExpression, Type: Class) (Syntax: 'new Class(x)')
IDynamicObjectCreationExpression (OperationKind.DynamicObjectCreationExpression, Type: Class) (Syntax: 'new Class(x)')
ApplicableSymbols(2):
Symbol: Class..ctor(Class x)
Symbol: Class..ctor(System.String x)
......
......@@ -4507,34 +4507,18 @@ internal sealed partial class LazyTypeParameterObjectCreationExpression : BaseTy
/// <remarks>
/// Represents a dynamically bound new/New expression.
/// </remarks>
internal abstract partial class BaseDynamicObjectCreationExpression : Operation, IHasDynamicArgumentsExpression, IDynamicObjectCreationExpression
internal abstract partial class HasDynamicArgumentsExpression : Operation, IHasDynamicArgumentsExpression
{
public BaseDynamicObjectCreationExpression(string name, ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(OperationKind.DynamicObjectCreationExpression, semanticModel, syntax, type, constantValue, isImplicit)
protected HasDynamicArgumentsExpression(OperationKind operationKind, ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(operationKind, semanticModel, syntax, type, constantValue, isImplicit)
{
MemberName = name;
ApplicableSymbols = applicableSymbols;
ArgumentNames = argumentNames;
ArgumentRefKinds = argumentRefKinds;
}
protected abstract ImmutableArray<IOperation> ArgumentsImpl { get; }
protected abstract IObjectOrCollectionInitializerExpression InitializerImpl { get; }
public override IEnumerable<IOperation> Children
{
get
{
foreach (var argument in Arguments)
{
yield return argument;
}
yield return Initializer;
}
}
/// <summary>
/// Name of the dynamically invoked member.
/// </summary>
public string MemberName { get; }
/// <summary>
/// List of applicable symbols that are dynamically bound.
/// </summary>
......@@ -4551,6 +4535,30 @@ public override IEnumerable<IOperation> Children
/// Dynamically bound arguments, excluding the instance argument.
/// </summary>
public ImmutableArray<IOperation> Arguments => Operation.SetParentOperation(ArgumentsImpl, this);
}
/// <remarks>
/// Represents a dynamically bound new/New expression.
/// </remarks>
internal abstract partial class BaseDynamicObjectCreationExpression : HasDynamicArgumentsExpression, IDynamicObjectCreationExpression
{
public BaseDynamicObjectCreationExpression(ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(OperationKind.DynamicObjectCreationExpression, applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
{
}
protected abstract IObjectOrCollectionInitializerExpression InitializerImpl { get; }
public override IEnumerable<IOperation> Children
{
get
{
foreach (var argument in Arguments)
{
yield return argument;
}
yield return Initializer;
}
}
/// <summary>
/// Object or collection initializer, if any.
/// </summary>
......@@ -4570,8 +4578,8 @@ public override void Accept(OperationVisitor visitor)
/// </remarks>
internal sealed partial class DynamicObjectCreationExpression : BaseDynamicObjectCreationExpression, IHasDynamicArgumentsExpression, IDynamicObjectCreationExpression
{
public DynamicObjectCreationExpression(string name, ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<IOperation> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, IObjectOrCollectionInitializerExpression initializer, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(name, applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
public DynamicObjectCreationExpression(ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<IOperation> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, IObjectOrCollectionInitializerExpression initializer, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
{
ArgumentsImpl = arguments;
InitializerImpl = initializer;
......@@ -4587,8 +4595,8 @@ internal sealed partial class LazyDynamicObjectCreationExpression : BaseDynamicO
{
private readonly Lazy<IObjectOrCollectionInitializerExpression> _lazyInitializer;
private readonly Lazy<ImmutableArray<IOperation>> _lazyArguments;
public LazyDynamicObjectCreationExpression(string name, ImmutableArray<ISymbol> applicableSymbols, Lazy<ImmutableArray<IOperation>> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, Lazy<IObjectOrCollectionInitializerExpression> initializer, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(name, applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
public LazyDynamicObjectCreationExpression(ImmutableArray<ISymbol> applicableSymbols, Lazy<ImmutableArray<IOperation>> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, Lazy<IObjectOrCollectionInitializerExpression> initializer, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
{
_lazyArguments = arguments ?? throw new System.ArgumentNullException(nameof(arguments));
_lazyInitializer = initializer ?? throw new System.ArgumentNullException(nameof(initializer));
......@@ -4598,19 +4606,15 @@ internal sealed partial class LazyDynamicObjectCreationExpression : BaseDynamicO
}
/// <remarks>
/// Represents a dynamically bound invocation expression.
/// Represents a dynamically bound invocation expression in C# and late bound invocation in VB.
/// </remarks>
internal abstract partial class BaseDynamicInvocationExpression : Operation, IHasDynamicArgumentsExpression, IDynamicInvocationExpression
internal abstract partial class BaseDynamicInvocationExpression : HasDynamicArgumentsExpression, IDynamicInvocationExpression
{
public BaseDynamicInvocationExpression(ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(OperationKind.DynamicInvocationExpression, semanticModel, syntax, type, constantValue, isImplicit)
base(OperationKind.DynamicInvocationExpression, applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
{
ApplicableSymbols = applicableSymbols;
ArgumentNames = argumentNames;
ArgumentRefKinds = argumentRefKinds;
}
protected abstract IOperation ExpressionImpl { get; }
protected abstract ImmutableArray<IOperation> ArgumentsImpl { get; }
public override IEnumerable<IOperation> Children
{
......@@ -4624,25 +4628,9 @@ public override IEnumerable<IOperation> Children
}
}
/// <summary>
/// Dynamically invoked expression, which could be a dynamic member access, dynamic delegate or an invalid expression.
/// Dynamically or late bound expression.
/// </summary>
public IOperation Expression => Operation.SetParentOperation(ExpressionImpl, this);
/// <summary>
/// List of applicable symbols that are dynamically bound.
/// </summary>
public ImmutableArray<ISymbol> ApplicableSymbols { get; }
/// <summary>
/// Optional argument names for named arguments.
/// </summary>
public ImmutableArray<string> ArgumentNames { get; }
/// <summary>
/// Optional argument ref kinds.
/// </summary>
public ImmutableArray<RefKind> ArgumentRefKinds { get; }
/// <summary>
/// Dynamically bound arguments, excluding the instance argument.
/// </summary>
public ImmutableArray<IOperation> Arguments => Operation.SetParentOperation(ArgumentsImpl, this);
public override void Accept(OperationVisitor visitor)
{
visitor.VisitDynamicInvocationExpression(this);
......@@ -4654,7 +4642,7 @@ public override void Accept(OperationVisitor visitor)
}
/// <remarks>
/// Represents a dynamically bound invocation expression.
/// Represents a dynamically bound invocation expression in C# and late bound invocation in VB.
/// </remarks>
internal sealed partial class DynamicInvocationExpression : BaseDynamicInvocationExpression, IHasDynamicArgumentsExpression, IDynamicInvocationExpression
{
......@@ -4669,7 +4657,7 @@ internal sealed partial class DynamicInvocationExpression : BaseDynamicInvocatio
}
/// <remarks>
/// Represents a dynamically bound invocation expression.
/// Represents a dynamically bound invocation expression in C# and late bound invocation in VB.
/// </remarks>
internal sealed partial class LazyDynamicInvocationExpression : BaseDynamicInvocationExpression, IHasDynamicArgumentsExpression, IDynamicInvocationExpression
{
......@@ -4686,19 +4674,15 @@ internal sealed partial class LazyDynamicInvocationExpression : BaseDynamicInvoc
}
/// <remarks>
/// Represents a dynamically referenced property or indexer expression.
/// Represents a dynamic indexer expression in C#.
/// </remarks>
internal abstract partial class BaseDynamicPropertyReferenceExpression : Operation, IHasDynamicArgumentsExpression, IDynamicPropertyReferenceExpression
internal abstract partial class BaseDynamicIndexerAccessExpression : HasDynamicArgumentsExpression, IDynamicIndexerAccessExpression
{
public BaseDynamicPropertyReferenceExpression(ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(OperationKind.DynamicPropertyReferenceExpression, semanticModel, syntax, type, constantValue, isImplicit)
public BaseDynamicIndexerAccessExpression(ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(OperationKind.DynamicIndexerAccessExpression, applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
{
ApplicableSymbols = applicableSymbols;
ArgumentNames = argumentNames;
ArgumentRefKinds = argumentRefKinds;
}
protected abstract IOperation ExpressionImpl { get; }
protected abstract ImmutableArray<IOperation> ArgumentsImpl { get; }
public override IEnumerable<IOperation> Children
{
......@@ -4712,41 +4696,25 @@ public override IEnumerable<IOperation> Children
}
}
/// <summary>
/// Dynamically accessed property reference.
/// Dynamically indexed expression.
/// </summary>
public IOperation Expression => Operation.SetParentOperation(ExpressionImpl, this);
/// <summary>
/// List of applicable symbols that are dynamically bound.
/// </summary>
public ImmutableArray<ISymbol> ApplicableSymbols { get; }
/// <summary>
/// Optional argument names for named arguments.
/// </summary>
public ImmutableArray<string> ArgumentNames { get; }
/// <summary>
/// Optional argument ref kinds.
/// </summary>
public ImmutableArray<RefKind> ArgumentRefKinds { get; }
/// <summary>
/// Dynamically bound arguments, excluding the instance argument.
/// </summary>
public ImmutableArray<IOperation> Arguments => Operation.SetParentOperation(ArgumentsImpl, this);
public override void Accept(OperationVisitor visitor)
{
visitor.VisitDynamicPropertyReferenceExpression(this);
visitor.VisitDynamicIndexerAccessExpression(this);
}
public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, TResult> visitor, TArgument argument)
{
return visitor.VisitDynamicPropertyReferenceExpression(this, argument);
return visitor.VisitDynamicIndexerAccessExpression(this, argument);
}
}
/// <remarks>
/// Represents a dynamically referenced property or indexer expression.
/// Represents a dynamic indexer expression in C#.
/// </remarks>
internal sealed partial class DynamicPropertyReferenceExpression : BaseDynamicPropertyReferenceExpression, IHasDynamicArgumentsExpression, IDynamicPropertyReferenceExpression
internal sealed partial class DynamicIndexerAccessExpression : BaseDynamicIndexerAccessExpression, IHasDynamicArgumentsExpression, IDynamicIndexerAccessExpression
{
public DynamicPropertyReferenceExpression(IOperation expression, ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<IOperation> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
public DynamicIndexerAccessExpression(IOperation expression, ImmutableArray<ISymbol> applicableSymbols, ImmutableArray<IOperation> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
{
ExpressionImpl = expression;
......@@ -4757,13 +4725,13 @@ internal sealed partial class DynamicPropertyReferenceExpression : BaseDynamicPr
}
/// <remarks>
/// Represents a dynamically referenced property or indexer expression.
/// Represents a dynamic indexer expression in C#.
/// </remarks>
internal sealed partial class LazyDynamicPropertyReferenceExpression : BaseDynamicPropertyReferenceExpression, IHasDynamicArgumentsExpression, IDynamicPropertyReferenceExpression
internal sealed partial class LazyDynamicIndexerAccessExpression : BaseDynamicIndexerAccessExpression, IHasDynamicArgumentsExpression, IDynamicIndexerAccessExpression
{
private readonly Lazy<IOperation> _lazyExpression;
private readonly Lazy<ImmutableArray<IOperation>> _lazyArguments;
public LazyDynamicPropertyReferenceExpression(Lazy<IOperation> expression, ImmutableArray<ISymbol> applicableSymbols, Lazy<ImmutableArray<IOperation>> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
public LazyDynamicIndexerAccessExpression(Lazy<IOperation> expression, ImmutableArray<ISymbol> applicableSymbols, Lazy<ImmutableArray<IOperation>> arguments, ImmutableArray<string> argumentNames, ImmutableArray<RefKind> argumentRefKinds, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) :
base(applicableSymbols, argumentNames, argumentRefKinds, semanticModel, syntax, type, constantValue, isImplicit)
{
_lazyExpression = expression ?? throw new System.ArgumentNullException(nameof(expression));
......
......@@ -3,16 +3,16 @@
namespace Microsoft.CodeAnalysis.Semantics
{
/// <summary>
/// Represents a dynamically referenced property or indexer expression.
/// Represents a dynamic indexer expression in C#.
/// </summary>
/// <remarks>
/// This interface is reserved for implementation by its associated APIs. We reserve the right to
/// change it in the future.
/// </remarks>
public interface IDynamicPropertyReferenceExpression : IHasDynamicArgumentsExpression
public interface IDynamicIndexerAccessExpression : IHasDynamicArgumentsExpression
{
/// <summary>
/// Dynamically accessed property reference.
/// Dynamically indexed expression.
/// </summary>
IOperation Expression { get; }
}
......
......@@ -3,7 +3,7 @@
namespace Microsoft.CodeAnalysis.Semantics
{
/// <summary>
/// Represents a dynamically bound invocation expression.
/// Represents a dynamically bound invocation expression in C# and late bound invocation in VB.
/// </summary>
/// <remarks>
/// This interface is reserved for implementation by its associated APIs. We reserve the right to
......@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Semantics
public interface IDynamicInvocationExpression : IHasDynamicArgumentsExpression
{
/// <summary>
/// Dynamically invoked expression, which could be a dynamic member access, dynamic delegate or an invalid expression.
/// Dynamically or late bound expression.
/// </summary>
IOperation Expression { get; }
}
......
......@@ -11,11 +11,6 @@ namespace Microsoft.CodeAnalysis.Semantics
/// </remarks>
public interface IDynamicObjectCreationExpression : IHasDynamicArgumentsExpression
{
/// <summary>
/// Name of the dynamically invoked member.
/// </summary>
string MemberName { get; }
/// <summary>
/// Object or collection initializer, if any.
/// </summary>
......
......@@ -19,16 +19,6 @@ public interface IHasDynamicArgumentsExpression : IOperation
/// Dynamically bound arguments, excluding the instance argument.
/// </summary>
ImmutableArray<IOperation> Arguments { get; }
/// <summary>
/// Optional argument names for named arguments.
/// </summary>
ImmutableArray<string> ArgumentNames { get; }
/// <summary>
/// Optional argument ref kinds.
/// </summary>
ImmutableArray<RefKind> ArgumentRefKinds { get; }
}
}
......@@ -396,17 +396,17 @@ public override IOperation VisitDynamicMemberReferenceExpression(IDynamicMemberR
public override IOperation VisitDynamicObjectCreationExpression(IDynamicObjectCreationExpression operation, object argument)
{
return new DynamicObjectCreationExpression(operation.MemberName, operation.ApplicableSymbols, VisitArray(operation.Arguments), operation.ArgumentNames, operation.ArgumentRefKinds, Visit(operation.Initializer), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
return new DynamicObjectCreationExpression(operation.ApplicableSymbols, VisitArray(operation.Arguments), ((HasDynamicArgumentsExpression)operation).ArgumentNames, ((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, Visit(operation.Initializer), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
}
public override IOperation VisitDynamicInvocationExpression(IDynamicInvocationExpression operation, object argument)
{
return new DynamicInvocationExpression(Visit(operation.Expression), operation.ApplicableSymbols, VisitArray(operation.Arguments), operation.ArgumentNames, operation.ArgumentRefKinds, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
return new DynamicInvocationExpression(Visit(operation.Expression), operation.ApplicableSymbols, VisitArray(operation.Arguments), ((HasDynamicArgumentsExpression)operation).ArgumentNames, ((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
}
public override IOperation VisitDynamicPropertyReferenceExpression(IDynamicPropertyReferenceExpression operation, object argument)
public override IOperation VisitDynamicIndexerAccessExpression(IDynamicIndexerAccessExpression operation, object argument)
{
return new DynamicPropertyReferenceExpression(Visit(operation.Expression), operation.ApplicableSymbols, VisitArray(operation.Arguments), operation.ArgumentNames, operation.ArgumentRefKinds, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
return new DynamicIndexerAccessExpression(Visit(operation.Expression), operation.ApplicableSymbols, VisitArray(operation.Arguments), ((HasDynamicArgumentsExpression)operation).ArgumentNames, ((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
}
public override IOperation VisitDefaultValueExpression(IDefaultValueExpression operation, object argument)
......
......@@ -17,6 +17,16 @@ public static partial class OperationExtensions
/// </summary>
public static bool HasErrors(this IOperation operation, Compilation compilation, CancellationToken cancellationToken = default(CancellationToken))
{
if (operation == null)
{
throw new ArgumentNullException(nameof(operation));
}
if (compilation == null)
{
throw new ArgumentNullException(nameof(compilation));
}
// once we made sure every operation has Syntax, we will remove this condition
if (operation.Syntax == null)
{
......@@ -80,6 +90,11 @@ private static IEnumerable<IOperation> Descendants(IOperation operation, bool in
public static IOperation GetRootOperation(this ISymbol symbol, CancellationToken cancellationToken = default(CancellationToken))
{
if (symbol == null)
{
throw new ArgumentNullException(nameof(symbol));
}
var symbolWithOperation = symbol as ISymbolWithOperation;
if (symbolWithOperation != null)
{
......@@ -93,6 +108,11 @@ public static IOperation GetRootOperation(this ISymbol symbol, CancellationToken
public static ImmutableArray<ILocalSymbol> GetDeclaredVariables(this IVariableDeclarationStatement declarationStatement)
{
if (declarationStatement == null)
{
throw new ArgumentNullException(nameof(declarationStatement));
}
var arrayBuilder = ArrayBuilder<ILocalSymbol>.GetInstance();
foreach (IVariableDeclaration group in declarationStatement.Declarations)
{
......@@ -104,6 +124,67 @@ public static ImmutableArray<ILocalSymbol> GetDeclaredVariables(this IVariableDe
return arrayBuilder.ToImmutableAndFree();
}
/// <summary>
/// Get an optional argument name for a named argument to the given <paramref name="dynamicExpression"/> at the given <paramref name="index"/>.
/// </summary>
/// <param name="dynamicExpression">Dynamic or late bound expression.</param>
/// <param name="index">Argument index.</param>
public static string GetArgumentName(this IHasDynamicArgumentsExpression dynamicExpression, int index)
{
if (dynamicExpression == null)
{
throw new ArgumentNullException(nameof(dynamicExpression));
}
var expression = (HasDynamicArgumentsExpression)dynamicExpression;
if (expression.ArgumentNames.IsDefaultOrEmpty)
{
return null;
}
if (index < 0 || index >= expression.ArgumentNames.Length)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
return expression.ArgumentNames[index];
}
/// <summary>
/// Get an optional argument <see cref="RefKind"/> for an argument at the given <paramref name="index"/> to the given <paramref name="dynamicExpression"/>.
/// Returns a non-null argument <see cref="RefKind"/> for C#.
/// Always returns null for VB as <see cref="RefKind"/> cannot be specified for an the argument in VB.
/// </summary>
/// <param name="dynamicExpression">Dynamic or late bound expression.</param>
/// <param name="index">Argument index.</param>
public static RefKind? GetArgumentRefKind(this IHasDynamicArgumentsExpression dynamicExpression, int index)
{
if (dynamicExpression == null)
{
throw new ArgumentNullException(nameof(dynamicExpression));
}
var expression = (HasDynamicArgumentsExpression)dynamicExpression;
if (expression.ArgumentRefKinds.IsDefault)
{
// VB case, arguments cannot have RefKind.
return null;
}
if (expression.ArgumentRefKinds.IsEmpty)
{
// C# case where no explicit RefKind was specified for any argument, hence all arguments have RefKind.None.
return RefKind.None;
}
if (index < 0 || index >= expression.ArgumentRefKinds.Length)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
return expression.ArgumentRefKinds[index];
}
}
internal interface ISymbolWithOperation
......
......@@ -143,8 +143,8 @@ public enum OperationKind
DynamicMemberReferenceExpression = 0x126,
/// <summary>Indicates an <see cref="IDynamicInvocationExpression"/>.</summary>
DynamicInvocationExpression = 0x127,
/// <summary>Indicates an <see cref="IDynamicPropertyReferenceExpression"/>.</summary>
DynamicPropertyReferenceExpression = 0x128,
/// <summary>Indicates an <see cref="IDynamicIndexerAccessExpression"/>.</summary>
DynamicIndexerAccessExpression = 0x128,
// Expressions that occur only in C#.
......
......@@ -335,7 +335,7 @@ public virtual void VisitDynamicInvocationExpression(IDynamicInvocationExpressio
DefaultVisit(operation);
}
public virtual void VisitDynamicPropertyReferenceExpression(IDynamicPropertyReferenceExpression operation)
public virtual void VisitDynamicIndexerAccessExpression(IDynamicIndexerAccessExpression operation)
{
DefaultVisit(operation);
}
......@@ -810,7 +810,7 @@ public virtual TResult VisitDynamicInvocationExpression(IDynamicInvocationExpres
return DefaultVisit(operation, argument);
}
public virtual TResult VisitDynamicPropertyReferenceExpression(IDynamicPropertyReferenceExpression operation, TArgument argument)
public virtual TResult VisitDynamicIndexerAccessExpression(IDynamicIndexerAccessExpression operation, TArgument argument)
{
return DefaultVisit(operation, argument);
}
......
......@@ -569,11 +569,9 @@ Namespace Microsoft.CodeAnalysis.Semantics
Private Function CreateBoundLateInvocationOperation(boundLateInvocation As BoundLateInvocation) As IOperation
Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundLateInvocation.Member))
Dim isDynamicPropertyReference = boundLateInvocation.MethodOrPropertyGroupOpt?.Kind = BoundKind.PropertyGroup
Dim applicableSymbols As ImmutableArray(Of ISymbol)
If boundLateInvocation.MethodOrPropertyGroupOpt IsNot Nothing Then
applicableSymbols = If(isDynamicPropertyReference,
applicableSymbols = If(boundLateInvocation.MethodOrPropertyGroupOpt.Kind = BoundKind.PropertyGroup,
DirectCast(boundLateInvocation.MethodOrPropertyGroupOpt, BoundPropertyGroup).Properties.As(Of ISymbol),
DirectCast(boundLateInvocation.MethodOrPropertyGroupOpt, BoundMethodGroup).Methods.As(Of ISymbol))
Else
......@@ -585,16 +583,13 @@ Namespace Microsoft.CodeAnalysis.Semantics
ImmutableArray(Of IOperation).Empty,
boundLateInvocation.ArgumentsOpt.SelectAsArray(Function(n) Create(n)))
End Function)
Dim argumentNames As ImmutableArray(Of String) = boundLateInvocation.ArgumentNamesOpt.NullToEmpty()
Dim argumentRefKinds As ImmutableArray(Of RefKind) = ImmutableArray(Of RefKind).Empty
Dim argumentNames As ImmutableArray(Of String) = boundLateInvocation.ArgumentNamesOpt
Dim argumentRefKinds As ImmutableArray(Of RefKind) = Nothing
Dim syntax As SyntaxNode = boundLateInvocation.Syntax
Dim type As ITypeSymbol = boundLateInvocation.Type
Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLateInvocation.ConstantValueOpt)
Dim isImplicit As Boolean = boundLateInvocation.WasCompilerGenerated
Return If(isDynamicPropertyReference,
New LazyDynamicPropertyReferenceExpression(expression, applicableSymbols, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, constantValue, isImplicit),
DirectCast(New LazyDynamicInvocationExpression(expression, applicableSymbols, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, constantValue, isImplicit), IOperation))
Return New LazyDynamicInvocationExpression(expression, applicableSymbols, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, constantValue, isImplicit)
End Function
Private Function CreateBoundObjectCreationExpressionOperation(boundObjectCreationExpression As BoundObjectCreationExpression) As IObjectCreationExpression
......
......@@ -9,7 +9,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
Inherits SemanticModelTestBase
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocation_Basic()
Public Sub DynamicInvocationExpression_Basic()
Dim source = <![CDATA[
Option Strict Off
......@@ -38,7 +38,7 @@ IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: S
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocation_MultipleApplicableSymbols()
Public Sub DynamicInvocationExpression_MultipleApplicableSymbols()
Dim source = <![CDATA[
Option Strict Off
......@@ -75,7 +75,7 @@ IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: S
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocation_MultipleArgumentsAndApplicableSymbols()
Public Sub DynamicInvocationExpression_MultipleArgumentsAndApplicableSymbols()
Dim source = <![CDATA[
Option Strict Off
......@@ -113,7 +113,7 @@ IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: S
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocation_ArgumentNames()
Public Sub DynamicInvocationExpression_ArgumentNames()
Dim source = <![CDATA[
Option Strict Off
......@@ -153,7 +153,7 @@ IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: S
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocation_ArgumentRefKinds()
Public Sub DynamicInvocationExpression_ArgumentRefKinds()
Dim source = <![CDATA[
Option Strict Off
Imports System.Runtime.InteropServices
......@@ -194,7 +194,7 @@ IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: S
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocation_OverloadResolutionFailure()
Public Sub DynamicInvocationExpression_OverloadResolutionFailure()
Dim source = <![CDATA[
Option Strict Off
......@@ -223,6 +223,235 @@ BC30516: Overload resolution failed because no accessible 'M2' accepts this numb
~~
]]>.Value
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocationExpression_PropertyGroup_MultipleApplicableSymbols()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object)
Dim x = c(d)'BIND:"c(d)"
End Sub
Default ReadOnly Property P1(x As Integer) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: System.Object) (Syntax: 'c(d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String) As System.Int32
Arguments(1):
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(0)
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocationExpression_PropertyGroup_MultipleArgumentsAndApplicableSymbols()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object)
Dim x = c(d, d)'BIND:"c(d, d)"
End Sub
Default ReadOnly Property P1(x As Integer, x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: System.Object) (Syntax: 'c(d, d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32, x2 As System.Object) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String, x2 As System.Object) As System.Int32
Arguments(2):
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(0)
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocationExpression_PropertyGroup_ArgumentNames()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object, e As Object)
Dim x = c(x2:=e, x:=d)'BIND:"c(x2:=e, x:=d)"
End Sub
Default ReadOnly Property P1(x As Integer, x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: System.Object) (Syntax: 'c(x2:=e, x:=d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32, x2 As System.Object) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String, x2 As System.Object) As System.Int32
Arguments(2):
IParameterReferenceExpression: e (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'e')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(2):
"x2"
"x"
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocationExpression_PropertyGroup_ArgumentRefKinds()
Dim source = <![CDATA[
Option Strict Off
Imports System.Runtime.InteropServices
Class C
Private Sub M(c As C, d As Object, e As Object)
Dim x = c(x2:=e, x:=d)'BIND:"c(x2:=e, x:=d)"
End Sub
Default ReadOnly Property P1(x As Integer, <Out> ByRef x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, <Out> ByRef x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicInvocationExpression (OperationKind.DynamicInvocationExpression, Type: System.Object) (Syntax: 'c(x2:=e, x:=d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32, x2 As System.Object) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String, x2 As System.Object) As System.Int32
Arguments(2):
IParameterReferenceExpression: e (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'e')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(2):
"x2"
"x"
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = <![CDATA[
BC30651: property parameters cannot be declared 'ByRef'.
Default ReadOnly Property P1(x As Integer, <Out> ByRef x2 As Object) As Integer
~~~~~
BC30651: property parameters cannot be declared 'ByRef'.
Default ReadOnly Property P1(x As String, <Out> ByRef x2 As Object) As Integer
~~~~~
]]>.Value
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicInvocationExpression_PropertyGroup_OverloadResolutionFailure()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object)
Dim x = c(c, d)'BIND:"c(c, d)"
End Sub
Default ReadOnly Property P1(x As Integer, x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IInvalidExpression (OperationKind.InvalidExpression, Type: System.Int32, IsInvalid) (Syntax: 'c(c, d)')
Children(3):
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'c')
IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
]]>.Value
Dim expectedDiagnostics = <![CDATA[
BC30518: Overload resolution failed because no accessible 'P1' can be called with these arguments:
'Public ReadOnly Default Property P1(x As Integer, x2 As Object) As Integer': Value of type 'C' cannot be converted to 'Integer'.
'Public ReadOnly Default Property P1(x As String, x2 As Object) As Integer': Value of type 'C' cannot be converted to 'String'.
Dim x = c(c, d)'BIND:"c(c, d)"
~
]]>.Value
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
End Class
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.CodeAnalysis.Test.Utilities
Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
Partial Public Class IOperationTests
Inherits SemanticModelTestBase
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicPropertyReference_MultipleApplicableSymbols()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object)
Dim x = c(d)'BIND:"c(d)"
End Sub
Default ReadOnly Property P1(x As Integer) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: System.Object) (Syntax: 'c(d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String) As System.Int32
Arguments(1):
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(0)
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicPropertyReference_MultipleArgumentsAndApplicableSymbols()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object)
Dim x = c(d, d)'BIND:"c(d, d)"
End Sub
Default ReadOnly Property P1(x As Integer, x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: System.Object) (Syntax: 'c(d, d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32, x2 As System.Object) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String, x2 As System.Object) As System.Int32
Arguments(2):
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(0)
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicPropertyReference_ArgumentNames()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object, e As Object)
Dim x = c(x2:=e, x:=d)'BIND:"c(x2:=e, x:=d)"
End Sub
Default ReadOnly Property P1(x As Integer, x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: System.Object) (Syntax: 'c(x2:=e, x:=d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32, x2 As System.Object) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String, x2 As System.Object) As System.Int32
Arguments(2):
IParameterReferenceExpression: e (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'e')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(2):
"x2"
"x"
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicPropertyReference_ArgumentRefKinds()
Dim source = <![CDATA[
Option Strict Off
Imports System.Runtime.InteropServices
Class C
Private Sub M(c As C, d As Object, e As Object)
Dim x = c(x2:=e, x:=d)'BIND:"c(x2:=e, x:=d)"
End Sub
Default ReadOnly Property P1(x As Integer, <Out> ByRef x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, <Out> ByRef x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IDynamicPropertyReferenceExpression (OperationKind.DynamicPropertyReferenceExpression, Type: System.Object) (Syntax: 'c(x2:=e, x:=d)')
Expression: IDynamicMemberReferenceExpression (Member Name: "P1", Containing Type: null) (OperationKind.DynamicMemberReferenceExpression, Type: System.Object) (Syntax: 'c')
Type Arguments(0)
Instance Receiver: IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
ApplicableSymbols(2):
Symbol: ReadOnly Property C.P1(x As System.Int32, x2 As System.Object) As System.Int32
Symbol: ReadOnly Property C.P1(x As System.String, x2 As System.Object) As System.Int32
Arguments(2):
IParameterReferenceExpression: e (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'e')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
ArgumentNames(2):
"x2"
"x"
ArgumentRefKinds(0)
]]>.Value
Dim expectedDiagnostics = <![CDATA[
BC30651: property parameters cannot be declared 'ByRef'.
Default ReadOnly Property P1(x As Integer, <Out> ByRef x2 As Object) As Integer
~~~~~
BC30651: property parameters cannot be declared 'ByRef'.
Default ReadOnly Property P1(x As String, <Out> ByRef x2 As Object) As Integer
~~~~~
]]>.Value
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub DynamicPropertyReference_OverloadResolutionFailure()
Dim source = <![CDATA[
Option Strict Off
Class C
Private Sub M(c As C, d As Object)
Dim x = c(c, d)'BIND:"c(c, d)"
End Sub
Default ReadOnly Property P1(x As Integer, x2 As Object) As Integer
Get
Return 1
End Get
End Property
Default ReadOnly Property P1(x As String, x2 As Object) As Integer
Get
Return 1
End Get
End Property
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IInvalidExpression (OperationKind.InvalidExpression, Type: System.Int32, IsInvalid) (Syntax: 'c(c, d)')
Children(3):
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'c')
IParameterReferenceExpression: c (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'c')
IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')
]]>.Value
Dim expectedDiagnostics = <![CDATA[
BC30518: Overload resolution failed because no accessible 'P1' can be called with these arguments:
'Public ReadOnly Default Property P1(x As Integer, x2 As Object) As Integer': Value of type 'C' cannot be converted to 'Integer'.
'Public ReadOnly Default Property P1(x As String, x2 As Object) As Integer': Value of type 'C' cannot be converted to 'String'.
Dim x = c(c, d)'BIND:"c(c, d)"
~
]]>.Value
VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
End Class
End Namespace
......@@ -261,12 +261,12 @@ private void Visit(IOperation operation, string header)
Unindent();
}
private void VisitArrayCommon<T>(IEnumerable<T> list, string header, bool logElementCount, Action<T> arrayElementVisitor)
private void VisitArrayCommon<T>(ImmutableArray<T> list, string header, bool logElementCount, Action<T> arrayElementVisitor)
{
Debug.Assert(!string.IsNullOrEmpty(header));
Indent();
if (!list.IsEmpty())
if (!list.IsDefaultOrEmpty)
{
var elementCount = logElementCount ? $"({list.Count()})" : string.Empty;
LogString($"{header}{elementCount}:");
......@@ -307,23 +307,32 @@ internal void VisitRefKindArrayElement(RefKind element)
LogNewLine();
}
private void VisitArray<T>(IEnumerable<T> list, string header, bool logElementCount)
private void VisitChildren(IOperation operation)
{
var children = operation.Children.WhereNotNull().ToImmutableArray();
if (!children.IsEmpty|| operation.Kind != OperationKind.None)
{
VisitArray(children, "Children", logElementCount: true);
}
}
private void VisitArray<T>(ImmutableArray<T> list, string header, bool logElementCount)
where T: IOperation
{
VisitArrayCommon(list, header, logElementCount, VisitOperationArrayElement);
}
private void VisitArray(IEnumerable<ISymbol> list, string header, bool logElementCount)
private void VisitArray(ImmutableArray<ISymbol> list, string header, bool logElementCount)
{
VisitArrayCommon(list, header, logElementCount, VisitSymbolArrayElement);
}
private void VisitArray(IEnumerable<string> list, string header, bool logElementCount)
private void VisitArray(ImmutableArray<string> list, string header, bool logElementCount)
{
VisitArrayCommon(list, header, logElementCount, VisitStringArrayElement);
}
private void VisitArray(IEnumerable<RefKind> list, string header, bool logElementCount)
private void VisitArray(ImmutableArray<RefKind> list, string header, bool logElementCount)
{
VisitArrayCommon(list, header, logElementCount, VisitRefKindArrayElement);
}
......@@ -338,11 +347,7 @@ internal override void VisitNoneOperation(IOperation operation)
LogString("IOperation: ");
LogCommonPropertiesAndNewLine(operation);
var children = operation.Children.WhereNotNull();
if (children.Any())
{
VisitArray(children, "Children", logElementCount: true);
}
VisitChildren(operation);
}
public override void VisitBlockStatement(IBlockStatement operation)
......@@ -617,10 +622,61 @@ private void VisitArguments(IHasArgumentsExpression operation)
private void VisitDynamicArguments(IHasDynamicArgumentsExpression operation)
{
VisitArray(operation.ApplicableSymbols, "ApplicableSymbols", logElementCount: true);
VisitArray(operation.Arguments, "Arguments", logElementCount: true);
VisitArray(operation.ArgumentNames, "ArgumentNames", logElementCount: true);
VisitArray(operation.ArgumentRefKinds, "ArgumentRefKinds", logElementCount: true);
var dynamicOperation = (HasDynamicArgumentsExpression)operation;
VisitArray(dynamicOperation.ApplicableSymbols, "ApplicableSymbols", logElementCount: true);
VisitArray(dynamicOperation.Arguments, "Arguments", logElementCount: true);
VisitArray(dynamicOperation.ArgumentNames, "ArgumentNames", logElementCount: true);
VisitArray(dynamicOperation.ArgumentRefKinds, "ArgumentRefKinds", logElementCount: true);
VerifyGetArgumentNamePublicApi(dynamicOperation, dynamicOperation.ArgumentNames);
VerifyGetArgumentRefKindPublicApi(dynamicOperation, dynamicOperation.ArgumentRefKinds);
}
private static void VerifyGetArgumentNamePublicApi(IHasDynamicArgumentsExpression operation, ImmutableArray<string> argumentNames)
{
var length = operation.Arguments.Length;
if (argumentNames.IsDefaultOrEmpty)
{
for (int i = 0; i < length; i++)
{
Assert.Null(operation.GetArgumentName(i));
}
}
else
{
Assert.Equal(length, argumentNames.Length);
for (var i = 0; i < length; i++)
{
Assert.Equal(argumentNames[i], operation.GetArgumentName(i));
}
}
}
private static void VerifyGetArgumentRefKindPublicApi(IHasDynamicArgumentsExpression operation, ImmutableArray<RefKind> argumentRefKinds)
{
var length = operation.Arguments.Length;
if (argumentRefKinds.IsDefault)
{
for (int i = 0; i < length; i++)
{
Assert.Null(operation.GetArgumentRefKind(i));
}
}
else if (argumentRefKinds.IsEmpty)
{
for (int i = 0; i < length; i++)
{
Assert.Equal(RefKind.None, operation.GetArgumentRefKind(i));
}
}
else
{
Assert.Equal(length, argumentRefKinds.Length);
for (var i = 0; i < length; i++)
{
Assert.Equal(argumentRefKinds[i], operation.GetArgumentRefKind(i));
}
}
}
public override void VisitArgument(IArgument operation)
......@@ -968,9 +1024,6 @@ public override void VisitAnonymousObjectCreationExpression(IAnonymousObjectCrea
public override void VisitDynamicObjectCreationExpression(IDynamicObjectCreationExpression operation)
{
LogString(nameof(IDynamicObjectCreationExpression));
var name = operation.MemberName;
LogString($" (Name: {operation.MemberName})");
LogCommonPropertiesAndNewLine(operation);
VisitDynamicArguments(operation);
......@@ -986,9 +1039,9 @@ public override void VisitDynamicInvocationExpression(IDynamicInvocationExpressi
VisitDynamicArguments(operation);
}
public override void VisitDynamicPropertyReferenceExpression(IDynamicPropertyReferenceExpression operation)
public override void VisitDynamicIndexerAccessExpression(IDynamicIndexerAccessExpression operation)
{
LogString(nameof(IDynamicPropertyReferenceExpression));
LogString(nameof(IDynamicIndexerAccessExpression));
LogCommonPropertiesAndNewLine(operation);
Visit(operation.Expression, "Expression");
......@@ -1180,7 +1233,7 @@ public override void VisitInvalidStatement(IInvalidStatement operation)
LogString(nameof(IInvalidStatement));
LogCommonPropertiesAndNewLine(operation);
VisitArray(operation.Children, "Children", logElementCount: true);
VisitChildren(operation);
}
public override void VisitInvalidExpression(IInvalidExpression operation)
......@@ -1188,7 +1241,7 @@ public override void VisitInvalidExpression(IInvalidExpression operation)
LogString(nameof(IInvalidExpression));
LogCommonPropertiesAndNewLine(operation);
VisitArray(operation.Children, "Children", logElementCount: true);
VisitChildren(operation);
}
public override void VisitIfStatement(IIfStatement operation)
......
......@@ -444,32 +444,33 @@ public override void VisitAnonymousObjectCreationExpression(IAnonymousObjectCrea
base.VisitAnonymousObjectCreationExpression(operation);
}
private void VisitDynamicArguments(IHasDynamicArgumentsExpression operation)
{
var dynamicOperation = (HasDynamicArgumentsExpression)operation;
var applicableSymbols = dynamicOperation.ApplicableSymbols;
var names = dynamicOperation.ArgumentNames;
var refKinds = dynamicOperation.ArgumentRefKinds;
}
public override void VisitDynamicObjectCreationExpression(IDynamicObjectCreationExpression operation)
{
var name = operation.MemberName;
var applicableSymbols = operation.ApplicableSymbols;
var names = operation.ArgumentNames;
var refKinds = operation.ArgumentRefKinds;
VisitDynamicArguments(operation);
base.VisitDynamicObjectCreationExpression(operation);
}
public override void VisitDynamicInvocationExpression(IDynamicInvocationExpression operation)
{
var applicableSymbols = operation.ApplicableSymbols;
var names = operation.ArgumentNames;
var refKinds = operation.ArgumentRefKinds;
VisitDynamicArguments(operation);
base.VisitDynamicInvocationExpression(operation);
}
public override void VisitDynamicPropertyReferenceExpression(IDynamicPropertyReferenceExpression operation)
public override void VisitDynamicIndexerAccessExpression(IDynamicIndexerAccessExpression operation)
{
var applicableSymbols = operation.ApplicableSymbols;
var names = operation.ArgumentNames;
var refKinds = operation.ArgumentRefKinds;
base.VisitDynamicPropertyReferenceExpression(operation);
VisitDynamicArguments(operation);
base.VisitDynamicIndexerAccessExpression(operation);
}
public override void VisitObjectOrCollectionInitializerExpression(IObjectOrCollectionInitializerExpression operation)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册