提交 71d47927 编写于 作者: G Gen Lu

Merge pull request #7352 from genlu/IOperationTree

Make all internal nodes of IOperation tree subtypes of IOperation
// 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 System;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis.Semantics;
namespace Microsoft.CodeAnalysis.CSharp
......@@ -124,7 +126,7 @@ ImmutableArray<IStatement> ToStatements(BoundStatement statement)
{
return ImmutableArray<IStatement>.Empty;
}
return ImmutableArray.Create<IStatement>(statement);
}
}
......@@ -142,7 +144,7 @@ partial class BoundForEachStatement : IForEachLoopStatement
protected override OperationKind StatementKind => OperationKind.LoopStatement;
}
partial class BoundSwitchStatement: ISwitchStatement
partial class BoundSwitchStatement : ISwitchStatement
{
IExpression ISwitchStatement.Value => this.BoundExpression;
......@@ -156,6 +158,8 @@ partial class BoundSwitchSection : ICase
ImmutableArray<ICaseClause> ICase.Clauses => this.BoundSwitchLabels.As<ICaseClause>();
ImmutableArray<IStatement> ICase.Body => this.Statements.As<IStatement>();
protected override OperationKind StatementKind => OperationKind.SwitchSection;
}
partial class BoundSwitchLabel : ISingleValueCaseClause
......@@ -200,6 +204,12 @@ BinaryOperationKind ISingleValueCaseClause.Equality
}
CaseKind ICaseClause.CaseKind => this.ExpressionOpt != null ? CaseKind.SingleValue : CaseKind.Default;
OperationKind IOperation.Kind => OperationKind.SingleValueCaseClause;
bool IOperation.IsInvalid => this.HasErrors;
SyntaxNode IOperation.Syntax => this.Syntax;
}
partial class BoundTryStatement : ITryStatement
......@@ -239,7 +249,7 @@ partial class BoundFixedStatement : IFixedStatement
protected override OperationKind StatementKind => OperationKind.FixedStatement;
}
partial class BoundUsingStatement: IUsingWithDeclarationStatement, IUsingWithExpressionStatement
partial class BoundUsingStatement : IUsingWithDeclarationStatement, IUsingWithExpressionStatement
{
IVariableDeclarationStatement IUsingWithDeclarationStatement.Variables => this.DeclarationsOpt;
......@@ -310,20 +320,38 @@ partial class BoundStateMachineScope
protected override OperationKind StatementKind => OperationKind.None;
}
partial class BoundLocalDeclaration : IVariableDeclarationStatement, IVariable
partial class BoundLocalDeclaration : IVariableDeclarationStatement
{
ImmutableArray<IVariable> IVariableDeclarationStatement.Variables => ImmutableArray.Create<IVariable>(this);
ILocalSymbol IVariable.Variable => this.LocalSymbol;
private static readonly ConditionalWeakTable<BoundLocalDeclaration, object> s_variablesMappings =
new ConditionalWeakTable<BoundLocalDeclaration, object>();
IExpression IVariable.InitialValue => this.InitializerOpt;
ImmutableArray<IVariable> IVariableDeclarationStatement.Variables
{
get
{
return (ImmutableArray<IVariable>) s_variablesMappings.GetValue(this,
declaration => ImmutableArray.Create<IVariable>(new VariableDeclaration(declaration.LocalSymbol, declaration.InitializerOpt, declaration.Syntax)));
}
}
protected override OperationKind StatementKind => OperationKind.VariableDeclarationStatement;
}
partial class BoundMultipleLocalDeclarations : IVariableDeclarationStatement
{
ImmutableArray<IVariable> IVariableDeclarationStatement.Variables => this.LocalDeclarations.As<IVariable>();
private static readonly ConditionalWeakTable<BoundMultipleLocalDeclarations, object> s_variablesMappings =
new ConditionalWeakTable<BoundMultipleLocalDeclarations, object>();
ImmutableArray<IVariable> IVariableDeclarationStatement.Variables
{
get
{
return (ImmutableArray<IVariable>)s_variablesMappings.GetValue(this,
multipleDeclarations =>
multipleDeclarations.LocalDeclarations.SelectAsArray(declaration =>
(IVariable)new VariableDeclaration(declaration.LocalSymbol, declaration.InitializerOpt, declaration.Syntax)));
}
}
protected override OperationKind StatementKind => OperationKind.VariableDeclarationStatement;
}
......
......@@ -255,14 +255,14 @@ public sealed class Binary : IBinaryOperatorExpression
{
public Binary(BinaryOperationKind binaryKind, IExpression left, IExpression right, ITypeSymbol resultType, SyntaxNode syntax)
{
this.BinaryKind = binaryKind;
this.BinaryOperationKind = binaryKind;
this.Left = left;
this.Right = right;
this.ResultType = resultType;
this.Syntax = syntax;
}
public BinaryOperationKind BinaryKind { get; }
public BinaryOperationKind BinaryOperationKind { get; }
public IExpression Left { get; }
......@@ -291,7 +291,7 @@ public ArrayCreation(IArrayTypeSymbol arrayType, ImmutableArray<IExpression> ele
{
_arrayType = arrayType;
this.DimensionSizes = ImmutableArray.Create<IExpression>(new IntegerLiteral(elementValues.Count(), null, syntax));
this.ElementValues = new DimensionInitializer(elementValues);
this.Initializer = new ArrayInitializer(elementValues, syntax, arrayType);
this.Syntax = syntax;
}
......@@ -301,68 +301,38 @@ public ArrayCreation(IArrayTypeSymbol arrayType, ImmutableArray<IExpression> ele
public ITypeSymbol ElementType => _arrayType.ElementType;
public IArrayInitializer ElementValues { get; }
public IArrayInitializer Initializer { get; }
public SyntaxNode Syntax { get; }
public OperationKind Kind => OperationKind.ArrayCreationExpression;
public bool IsInvalid => IsInvalidInitializer(ElementValues);
public bool IsInvalid => IsInvalidInitializer(Initializer);
static bool IsInvalidInitializer(IArrayInitializer initializer)
{
switch (initializer.ArrayClass)
{
case ArrayInitializerKind.Dimension:
foreach (IArrayInitializer element in ((IDimensionArrayInitializer)initializer).ElementValues)
{
if (IsInvalidInitializer(element))
{
return true;
}
}
break;
case ArrayInitializerKind.Expression:
return ((IExpressionArrayInitializer)initializer).ElementValue.IsInvalid;
}
return false;
}
static bool IsInvalidInitializer(IArrayInitializer initializer) => initializer.IsInvalid;
public Optional<object> ConstantValue => default(Optional<object>);
private class DimensionInitializer : IDimensionArrayInitializer
private class ArrayInitializer : IArrayInitializer
{
private readonly ImmutableArray<IArrayInitializer> _elementValues;
public DimensionInitializer(ImmutableArray<IExpression> elementValues)
public ArrayInitializer(ImmutableArray<IExpression> elementValues, SyntaxNode syntax, ITypeSymbol arrayType)
{
ArrayBuilder<IArrayInitializer> builder = ArrayBuilder<IArrayInitializer>.GetInstance();
foreach (IExpression element in elementValues)
{
builder.Add(new ExpressionInitializer(element));
}
_elementValues = builder.ToImmutableAndFree();
ElementValues = elementValues;
Syntax = syntax;
ResultType = arrayType;
}
public ArrayInitializerKind ArrayClass => ArrayInitializerKind.Dimension;
public ImmutableArray<IExpression> ElementValues { get; }
public ImmutableArray<IArrayInitializer> ElementValues => _elementValues;
}
public bool IsInvalid => ElementValues.Any(v => v.IsInvalid);
private class ExpressionInitializer : IExpressionArrayInitializer
{
public ExpressionInitializer(IExpression expression)
{
ElementValue = expression;
}
public OperationKind Kind => OperationKind.ArrayInitializer;
public ArrayInitializerKind ArrayClass => ArrayInitializerKind.Expression;
public ITypeSymbol ResultType { get; }
public IExpression ElementValue { get; }
public SyntaxNode Syntax { get; }
public Optional<object> ConstantValue => default(Optional<object>);
}
}
......
......@@ -59,12 +59,12 @@ public interface IInvocationExpression : IExpression
/// <summary>
/// Represents an argument in a method invocation.
/// </summary>
public interface IArgument
public interface IArgument : IOperation
{
/// <summary>
/// Kind of argument.
/// </summary>
ArgumentKind Kind { get; }
ArgumentKind ArgumentKind { get; }
/// <summary>
/// Parameter the argument matches.
/// </summary>
......@@ -329,7 +329,7 @@ public interface IUnaryOperatorExpression : IHasOperatorExpression
/// <summary>
/// Kind of unary operation.
/// </summary>
UnaryOperationKind UnaryKind { get; }
UnaryOperationKind UnaryOperationKind { get; }
/// <summary>
/// Single operand.
/// </summary>
......@@ -418,7 +418,7 @@ public interface IBinaryOperatorExpression : IHasOperatorExpression
/// <summary>
/// Kind of binary operation.
/// </summary>
BinaryOperationKind BinaryKind { get; }
BinaryOperationKind BinaryOperationKind { get; }
/// <summary>
/// Left operand.
/// </summary>
......@@ -620,7 +620,7 @@ public interface IConversionExpression : IHasOperatorExpression
/// <summary>
/// Kind of conversion.
/// </summary>
ConversionKind Conversion { get; }
ConversionKind ConversionKind { get; }
/// <summary>
/// True if and only if the conversion is indicated explicity by a cast operation in the source code.
/// </summary>
......@@ -712,7 +712,7 @@ public interface ITypeOperationExpression : IExpression
/// <summary>
/// Kind of type operation.
/// </summary>
TypeOperationKind TypeOperationClass { get; }
TypeOperationKind TypeOperationKind { get; }
/// <summary>
/// Type operand.
/// </summary>
......@@ -798,9 +798,12 @@ public interface IObjectCreationExpression : IExpression
ImmutableArray<IMemberInitializer> MemberInitializers { get; }
}
public interface IMemberInitializer
/// <summary>
/// Represents an object member initializer.
/// </summary>
public interface IMemberInitializer : IOperation
{
MemberInitializerKind MemberClass { get; }
MemberInitializerKind MemberInitializerKind { get; }
IExpression Value { get; }
}
......@@ -851,49 +854,18 @@ public interface IArrayCreationExpression : IExpression
/// <summary>
/// Values of elements of the created array instance.
/// </summary>
IArrayInitializer ElementValues { get; }
IArrayInitializer Initializer { get; }
}
/// <summary>
/// Represents the initialization of an array instance.
/// </summary>
public interface IArrayInitializer
public interface IArrayInitializer : IExpression
{
/// <summary>
/// Kind of array initialization.
/// </summary>
ArrayInitializerKind ArrayClass { get; }
}
/// <summary>
/// Kinds of array initializers.
/// </summary>
public enum ArrayInitializerKind
{
/// <summary>
/// Initializer specifies a single element value.
/// </summary>
Expression,
/// <summary>
/// Initializer specifies multiple elements of a dimension of the array.
/// Values to initialize array elements.
/// </summary>
Dimension
}
/// <summary>
/// Represents an initialization of a single element of an array instance.
/// </summary>
public interface IExpressionArrayInitializer : IArrayInitializer
{
IExpression ElementValue { get; }
}
/// <summary>
/// Represents an initialization of a single dimension of an array instance.
/// </summary>
public interface IDimensionArrayInitializer : IArrayInitializer
{
ImmutableArray<IArrayInitializer> ElementValues { get; }
ImmutableArray<IExpression> ElementValues { get; }
}
/// <summary>
......
......@@ -106,6 +106,16 @@ public enum OperationKind
// Newly added
ConditionalAccessExpression,
IncrementExpression
IncrementExpression,
Argument,
FieldInitializer,
PropertyInitializer,
ArrayInitializer,
VariableDeclaration,
SwitchSection,
SingleValueCaseClause,
RelationalCaseClause,
RangeCaseClause
}
}
......@@ -40,7 +40,7 @@ public interface IVariableDeclarationStatement : IStatement
/// <summary>
/// Represents a local variable declaration.
/// </summary>
public interface IVariable
public interface IVariable : IOperation
{
/// <summary>
/// Variable declared by the declaration.
......@@ -70,7 +70,7 @@ public interface ISwitchStatement : IStatement
/// <summary>
/// Represents a C# case or VB Case statement.
/// </summary>
public interface ICase
public interface ICase : IStatement
{
/// <summary>
/// Clauses of the case. For C# there is one clause per case, but for VB there can be multiple.
......@@ -85,7 +85,7 @@ public interface ICase
/// <summary>
/// Represents a clause of a C# case or a VB Case.
/// </summary>
public interface ICaseClause
public interface ICaseClause : IOperation
{
/// <summary>
/// Kind of the clause.
......
// 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 System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace Microsoft.CodeAnalysis.Semantics
{
internal sealed class VariableDeclaration : IVariable
{
public VariableDeclaration(ILocalSymbol variable, IExpression initialValue, SyntaxNode syntax)
{
Variable = variable;
InitialValue = initialValue;
Syntax = syntax;
}
public ILocalSymbol Variable { get; }
public IExpression InitialValue { get; }
public bool IsInvalid => Variable == null || (InitialValue != null && InitialValue.IsInvalid);
public OperationKind Kind => OperationKind.VariableDeclaration;
public SyntaxNode Syntax { get; }
}
}
\ No newline at end of file
......@@ -90,12 +90,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Private Shared ReadOnly CaseElseMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundCaseStatement, Object)
Private ReadOnly Property IClauses As ImmutableArray(Of ICaseClause) Implements ICase.Clauses
Get
' `CaseElseClauseSyntax` is bound to `BoundCaseStatement` with an empty list of case clauses,
' so we explicitly create an IOperation node for Case-Else clause to differentiate it from Case clause.
If Me.CaseStatement.CaseClauses.IsEmpty AndAlso Me.CaseStatement.Syntax.Kind() = SyntaxKind.CaseElseStatement Then
Return ImmutableArray.Create(CaseElseClause)
Dim caseElse = CaseElseMappings.GetValue(Me.CaseStatement, Function(caseStatement) ImmutableArray.Create(Of ICaseClause)(New CaseElse(caseStatement)))
Return DirectCast(caseElse, ImmutableArray(Of ICaseClause))
End If
Return Me.CaseStatement.CaseClauses.As(Of ICaseClause)()
......@@ -103,13 +106,48 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Property
Protected Overrides Function StatementKind() As OperationKind
Return OperationKind.None
Return OperationKind.SwitchSection
End Function
Private Shared CaseElseClause As ICaseClause = New CaseElse
Private Class CaseElse
Implements ICaseClause
Implements ISingleValueCaseClause
Private _boundCaseStatement As BoundCaseStatement
Public Sub New(boundCaseStatement As BoundCaseStatement)
_boundCaseStatement = boundCaseStatement
End Sub
Public ReadOnly Property Equality As BinaryOperationKind Implements ISingleValueCaseClause.Equality
Get
Return BinaryOperationKind.None
End Get
End Property
Public ReadOnly Property Value As IExpression Implements ISingleValueCaseClause.Value
Get
Return Nothing
End Get
End Property
Public ReadOnly Property IsInvalid As Boolean Implements IOperation.IsInvalid
Get
Return _boundCaseStatement.HasErrors
End Get
End Property
Public ReadOnly Property Kind As OperationKind Implements IOperation.Kind
Get
Return OperationKind.SingleValueCaseClause
End Get
End Property
Public ReadOnly Property Syntax As SyntaxNode Implements IOperation.Syntax
Get
Return _boundCaseStatement.Syntax
End Get
End Property
Private ReadOnly Property ICaseClass As CaseKind Implements ICaseClause.CaseKind
Get
Return CaseKind.Default
......@@ -122,7 +160,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Partial Class BoundCaseClause
Implements ICaseClause
Protected MustOverride ReadOnly Property ICaseClass As CaseKind Implements ICaseClause.CaseKind
Private ReadOnly Property IIsInvalid As Boolean Implements IOperation.IsInvalid
Get
Return Me.HasErrors
End Get
End Property
Private ReadOnly Property ISyntax As SyntaxNode Implements IOperation.Syntax
Get
Return Me.Syntax
End Get
End Property
Protected MustOverride ReadOnly Property IKind As OperationKind Implements IOperation.Kind
Protected MustOverride ReadOnly Property ICaseKind As CaseKind Implements ICaseClause.CaseKind
End Class
Partial Class BoundSimpleCaseClause
......@@ -170,7 +223,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Protected Overrides ReadOnly Property ICaseClass As CaseKind
Protected Overrides ReadOnly Property IKind As OperationKind
Get
Return OperationKind.SingleValueCaseClause
End Get
End Property
Protected Overrides ReadOnly Property ICaseKind As CaseKind
Get
Return CaseKind.SingleValue
End Get
......@@ -214,7 +273,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Protected Overrides ReadOnly Property ICaseClass As CaseKind
Protected Overrides ReadOnly Property IKind As OperationKind
Get
Return OperationKind.RangeCaseClause
End Get
End Property
Protected Overrides ReadOnly Property ICaseKind As CaseKind
Get
Return CaseKind.Range
End Get
......@@ -248,7 +313,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Protected Overrides ReadOnly Property ICaseClass As CaseKind
Protected Overrides ReadOnly Property IKind As OperationKind
Get
Return OperationKind.RelationalCaseClause
End Get
End Property
Protected Overrides ReadOnly Property ICaseKind As CaseKind
Get
Return CaseKind.Relational
End Get
......@@ -305,11 +376,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Partial Class BoundForToStatement
Implements IForLoopStatement
Private Shared LoopBottomMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, Object)
Private Shared ReadOnly s_loopBottomMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, Object)
Private ReadOnly Property IAtLoopBottom As ImmutableArray(Of IStatement) Implements IForLoopStatement.AtLoopBottom
Get
Dim result = LoopBottomMappings.GetValue(
Dim result = s_loopBottomMappings.GetValue(
Me,
Function(BoundFor)
Dim statements As ArrayBuilder(Of IStatement) = ArrayBuilder(Of IStatement).GetInstance()
......@@ -341,11 +412,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Private Shared LoopTopMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, Object)
Private Shared ReadOnly s_loopTopMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, Object)
Private ReadOnly Property IBefore As ImmutableArray(Of IStatement) Implements IForLoopStatement.Before
Get
Dim result = LoopTopMappings.GetValue(
Dim result = s_loopTopMappings.GetValue(
Me,
Function(BoundFor)
Dim statements As ArrayBuilder(Of IStatement) = ArrayBuilder(Of IStatement).GetInstance()
......@@ -379,11 +450,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Private Shared LoopConditionMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, IExpression)
Private Shared ReadOnly s_loopConditionMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, IExpression)
Private ReadOnly Property ICondition As IExpression Implements IForWhileUntilLoopStatement.Condition
Get
Return LoopConditionMappings.GetValue(
Return s_loopConditionMappings.GetValue(
Me,
Function(BoundFor)
Dim limitValue As IExpression = If(BoundFor.LimitValue.IsConstant, DirectCast(BoundFor.LimitValue, IExpression), New Temporary(SyntheticLocalKind.ForLoopLimitValue, BoundFor, BoundFor.LimitValue))
......@@ -700,75 +771,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
End Class
Partial Class BoundLocalDeclarationBase
Implements IVariable
Protected MustOverride ReadOnly Property IInitialValue As IExpression Implements IVariable.InitialValue
Protected MustOverride ReadOnly Property IVariable As ILocalSymbol Implements IVariable.Variable
End Class
Partial Class BoundLocalDeclaration
Implements IVariableDeclarationStatement
Private ReadOnly Property IVariables As ImmutableArray(Of IVariable) Implements IVariableDeclarationStatement.Variables
Get
Return ImmutableArray.Create(Of IVariable)(Me)
End Get
End Property
Protected Overrides ReadOnly Property IInitialValue As IExpression
Get
Return Me.InitializerOpt
End Get
End Property
Protected Overrides ReadOnly Property IVariable As ILocalSymbol
Get
Return Me.LocalSymbol
End Get
End Property
Protected Overrides Function StatementKind() As OperationKind
Return OperationKind.VariableDeclarationStatement
End Function
End Class
Partial Class BoundAsNewLocalDeclarations
Implements IVariableDeclarationStatement
Private ReadOnly Property IVariables As ImmutableArray(Of IVariable) Implements IVariableDeclarationStatement.Variables
Get
Return Me.LocalDeclarations.As(Of IVariable)()
End Get
End Property
Protected Overrides ReadOnly Property IInitialValue As IExpression
Get
Return Me.Initializer
End Get
End Property
Protected Overrides ReadOnly Property IVariable As ILocalSymbol
Get
' ZZZ Get clear about what's happening in the VB bound trees. BoundAsNewLocalDeclarations has multiple symbols and
' inherits from BoundLocalDeclarationBase, which occurs multiply in BoundDimStatement.
Dim local As BoundLocalDeclaration = Me.LocalDeclarations.FirstOrDefault()
Return If(local IsNot Nothing, local.LocalSymbol, Nothing)
End Get
End Property
Protected Overrides Function StatementKind() As OperationKind
Return OperationKind.VariableDeclarationStatement
End Function
End Class
Partial Class BoundDimStatement
Implements IVariableDeclarationStatement
Private Shared ReadOnly s_variablesMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundDimStatement, Object)
Private ReadOnly Property IVariables As ImmutableArray(Of IVariable) Implements IVariableDeclarationStatement.Variables
Get
Return Me.LocalDeclarations.As(Of IVariable)()
Dim variables = s_variablesMappings.GetValue(Me, Function(dimStatement)
Dim builder = ArrayBuilder(Of IVariable).GetInstance()
For Each base In dimStatement.LocalDeclarations
If base.Kind = BoundKind.LocalDeclaration Then
Dim declaration = DirectCast(base, BoundLocalDeclaration)
builder.Add(New VariableDeclaration(declaration.LocalSymbol, declaration.InitializerOpt, declaration.Syntax))
ElseIf base.Kind = BoundKind.AsNewLocalDeclarations Then
Dim asNewDeclarations = DirectCast(base, BoundAsNewLocalDeclarations)
For Each asNewDeclaration In asNewDeclarations.LocalDeclarations
builder.Add(New VariableDeclaration(asNewDeclaration.LocalSymbol, asNewDeclarations.Initializer, asNewDeclaration.Syntax))
Next
End If
Next
Return builder.ToImmutableAndFree()
End Function
)
Return DirectCast(variables, ImmutableArray(Of IVariable))
End Get
End Property
......@@ -931,11 +957,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Private Shared VariablesMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundUsingStatement, Variables)
Private Shared ReadOnly s_variablesMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundUsingStatement, Variables)
Private ReadOnly Property IVariables As IVariableDeclarationStatement Implements IUsingWithDeclarationStatement.Variables
Get
Return VariablesMappings.GetValue(
Return s_variablesMappings.GetValue(
Me,
Function(BoundUsing)
Return New Variables(BoundUsing.ResourceList.As(Of IVariable))
......@@ -1003,69 +1029,111 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Class
Partial Class BoundAddRemoveHandlerStatement
Implements IEventAssignmentExpression
Implements IExpressionStatement
Protected MustOverride ReadOnly Property IAdds As Boolean Implements IEventAssignmentExpression.Adds
Protected Shared ReadOnly s_expressionsMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundAddRemoveHandlerStatement, IEventAssignmentExpression)
Private ReadOnly Property IConstantValue As [Optional](Of Object) Implements IExpression.ConstantValue
Get
Return New [Optional](Of Object)()
End Get
End Property
Protected Overrides Function StatementKind() As OperationKind
Return OperationKind.ExpressionStatement
End Function
Private ReadOnly Property IEvent As IEventSymbol Implements IEventAssignmentExpression.Event
Get
Dim eventAccess As BoundEventAccess = TryCast(Me.EventAccess, BoundEventAccess)
If eventAccess IsNot Nothing Then
Return eventAccess.EventSymbol
End If
Protected MustOverride ReadOnly Property IExpression As IExpression Implements IExpressionStatement.Expression
Return Nothing
End Get
End Property
Protected Class EventAssignmentExpression
Implements IEventAssignmentExpression
Private ReadOnly Property IEventInstance As IExpression Implements IEventAssignmentExpression.EventInstance
Get
Dim eventAccess As BoundEventAccess = TryCast(Me.EventAccess, BoundEventAccess)
If eventAccess IsNot Nothing Then
Return eventAccess.ReceiverOpt
End If
Private ReadOnly _statement As BoundAddRemoveHandlerStatement
Private ReadOnly _adds As Boolean
Return Nothing
End Get
End Property
Public Sub New(statement As BoundAddRemoveHandlerStatement, adds As Boolean)
_statement = statement
_adds = adds
End Sub
Private ReadOnly Property IResultType As ITypeSymbol Implements IExpression.ResultType
Get
Return Nothing
End Get
End Property
Public ReadOnly Property Adds As Boolean Implements IEventAssignmentExpression.Adds
Get
Return _adds
End Get
End Property
Private ReadOnly Property IHandlerValue As IExpression Implements IEventAssignmentExpression.HandlerValue
Get
Return Me.Handler
End Get
End Property
Public ReadOnly Property ConstantValue As [Optional](Of Object) Implements IExpression.ConstantValue
Get
Return New [Optional](Of Object)()
End Get
End Property
Protected Overrides Function StatementKind() As OperationKind
Return OperationKind.EventAssignmentExpression
End Function
Public ReadOnly Property [Event] As IEventSymbol Implements IEventAssignmentExpression.Event
Get
Dim eventAccess As BoundEventAccess = TryCast(_statement.EventAccess, BoundEventAccess)
If eventAccess IsNot Nothing Then
Return eventAccess.EventSymbol
End If
Return Nothing
End Get
End Property
Public ReadOnly Property EventInstance As IExpression Implements IEventAssignmentExpression.EventInstance
Get
Dim eventAccess As BoundEventAccess = TryCast(_statement.EventAccess, BoundEventAccess)
If eventAccess IsNot Nothing Then
Return eventAccess.ReceiverOpt
End If
Return Nothing
End Get
End Property
Public ReadOnly Property HandlerValue As IExpression Implements IEventAssignmentExpression.HandlerValue
Get
Return _statement.Handler
End Get
End Property
Public ReadOnly Property IsInvalid As Boolean Implements IOperation.IsInvalid
Get
Return _statement.HasErrors
End Get
End Property
Public ReadOnly Property Kind As OperationKind Implements IOperation.Kind
Get
Return OperationKind.EventAssignmentExpression
End Get
End Property
Public ReadOnly Property ResultType As ITypeSymbol Implements IExpression.ResultType
Get
Return Nothing
End Get
End Property
Public ReadOnly Property Syntax As SyntaxNode Implements IOperation.Syntax
Get
Return _statement.Syntax
End Get
End Property
End Class
End Class
Partial Class BoundAddHandlerStatement
Protected Overrides ReadOnly Property IAdds As Boolean
Protected Overrides ReadOnly Property IExpression As IExpression
Get
Return True
Return s_expressionsMappings.GetValue(Me, Function(statement)
Return New EventAssignmentExpression(statement, True)
End Function)
End Get
End Property
End Class
Partial Class BoundRemoveHandlerStatement
Protected Overrides ReadOnly Property IAdds As Boolean
Protected Overrides ReadOnly Property IExpression As IExpression
Get
Return False
Return s_expressionsMappings.GetValue(Me, Function(statement)
Return New EventAssignmentExpression(statement, False)
End Function)
End Get
End Property
End Class
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册