Statement.vb 73.4 KB
Newer Older
J
John Hamby 已提交
1 2 3 4 5 6 7 8
' 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 System.Collections.Immutable
Imports Microsoft.CodeAnalysis.Semantics
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols

Namespace Microsoft.CodeAnalysis.VisualBasic

J
John Hamby 已提交
9
    Partial Friend Class BoundStatement
10
        Implements IOperation
J
John Hamby 已提交
11 12 13 14 15 16 17

        Private ReadOnly Property IKind As OperationKind Implements IOperation.Kind
            Get
                Return Me.StatementKind()
            End Get
        End Property

18
        Private ReadOnly Property IIsInvalid As Boolean Implements IOperation.IsInvalid
19 20 21 22 23
            Get
                Return Me.HasErrors
            End Get
        End Property

J
John Hamby 已提交
24 25 26 27 28 29
        Private ReadOnly Property ISyntax As SyntaxNode Implements IOperation.Syntax
            Get
                Return Me.Syntax
            End Get
        End Property

J
John Hamby 已提交
30 31 32 33 34 35 36 37 38 39 40 41
        Private ReadOnly Property IType As ITypeSymbol Implements IOperation.Type
            Get
                Return Nothing
            End Get
        End Property

        Private ReadOnly Property IConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
            Get
                Return New [Optional](Of Object)()
            End Get
        End Property

42
        Protected MustOverride Function StatementKind() As OperationKind
G
Gen Lu 已提交
43

44
        Public MustOverride Overloads Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
45

46
        Public MustOverride Overloads Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
J
John Hamby 已提交
47 48
    End Class

C
CyrusNajmabadi 已提交
49
    Friend Partial Class BoundIfStatement
J
John Hamby 已提交
50 51
        Implements IIfStatement

J
John Hamby 已提交
52
        Private ReadOnly Property ICondition As IOperation Implements IIfStatement.Condition
J
John Hamby 已提交
53 54 55 56 57
            Get
                Return Me.Condition
            End Get
        End Property

J
John Hamby 已提交
58
        Private ReadOnly Property IIfTrue As IOperation Implements IIfStatement.IfTrueStatement
J
John Hamby 已提交
59 60 61 62 63
            Get
                Return Me.Consequence
            End Get
        End Property

J
John Hamby 已提交
64
        Private ReadOnly Property IIfFalse As IOperation Implements IIfStatement.IfFalseStatement
J
John Hamby 已提交
65 66 67 68 69 70 71 72 73
            Get
                Return Me.AlternativeOpt
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.IfStatement
        End Function

74
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
75 76
            visitor.VisitIfStatement(Me)
        End Sub
77

78
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
79
            Return visitor.VisitIfStatement(Me, argument)
80
        End Function
J
John Hamby 已提交
81 82
    End Class

C
CyrusNajmabadi 已提交
83
    Friend Partial Class BoundSelectStatement
J
John Hamby 已提交
84 85
        Implements ISwitchStatement

86
        Private Shared ReadOnly s_caseBlocksMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundSelectStatement, Object)
G
Gen Lu 已提交
87

88
        Private ReadOnly Property ICases As ImmutableArray(Of ISwitchCase) Implements ISwitchStatement.Cases
J
John Hamby 已提交
89
            Get
90 91
                Dim cases = s_caseBlocksMappings.GetValue(Me, Function(boundSelect)
                                                                  Return boundSelect.CaseBlocks.SelectAsArray(Function(boundCaseBlock)
92
                                                                                                                  Return DirectCast(New CaseBlock(boundCaseBlock), ISwitchCase)
93 94
                                                                                                              End Function)
                                                              End Function)
95
                Return DirectCast(cases, ImmutableArray(Of ISwitchCase))
J
John Hamby 已提交
96 97 98
            End Get
        End Property

J
John Hamby 已提交
99
        Private ReadOnly Property IValue As IOperation Implements ISwitchStatement.Value
J
John Hamby 已提交
100 101 102 103 104 105 106 107
            Get
                Return Me.ExpressionStatement.Expression
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.SwitchStatement
        End Function
G
Gen Lu 已提交
108

109
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
110 111
            visitor.VisitSwitchStatement(Me)
        End Sub
112

113
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
114
            Return visitor.VisitSwitchStatement(Me, argument)
115
        End Function
J
John Hamby 已提交
116

117
        Private NotInheritable Class CaseBlock
118
            Implements ISwitchCase
J
John Hamby 已提交
119

G
Gen Lu 已提交
120
            Private ReadOnly _clauses As ImmutableArray(Of ICaseClause)
121
            Private ReadOnly _body As ImmutableArray(Of IOperation)
G
Gen Lu 已提交
122 123
            Private ReadOnly _isInvalid As Boolean
            Private ReadOnly _syntax As SyntaxNode
124

G
Gen Lu 已提交
125
            Public Sub New(boundCaseBlock As BoundCaseBlock)
G
Gen Lu 已提交
126 127
                ' `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.
G
Gen Lu 已提交
128 129 130 131 132
                Dim caseStatement = boundCaseBlock.CaseStatement
                If caseStatement.CaseClauses.IsEmpty AndAlso caseStatement.Syntax.Kind() = SyntaxKind.CaseElseStatement Then
                    _clauses = ImmutableArray.Create(Of ICaseClause)(New CaseElse(caseStatement))
                Else
                    _clauses = caseStatement.CaseClauses.As(Of ICaseClause)()
J
John Hamby 已提交
133 134
                End If

135
                _body = ImmutableArray.Create(Of IOperation)(boundCaseBlock.Body)
G
Gen Lu 已提交
136 137
                _isInvalid = boundCaseBlock.HasErrors
                _syntax = boundCaseBlock.Syntax
138 139
            End Sub

140
            Public Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
141
                visitor.VisitSwitchCase(Me)
142 143
            End Sub

144
            Public Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
145
                Return visitor.VisitSwitchCase(Me, argument)
146 147
            End Function

148
            Public ReadOnly Property Body As ImmutableArray(Of IOperation) Implements ISwitchCase.Body
149
                Get
G
Gen Lu 已提交
150
                    Return _body
151 152 153
                End Get
            End Property

154
            Public ReadOnly Property Clauses As ImmutableArray(Of ICaseClause) Implements ISwitchCase.Clauses
155
                Get
G
Gen Lu 已提交
156
                    Return _clauses
157 158 159 160 161
                End Get
            End Property

            Public ReadOnly Property IsInvalid As Boolean Implements IOperation.IsInvalid
                Get
G
Gen Lu 已提交
162
                    Return _isInvalid
163 164 165 166 167
                End Get
            End Property

            Public ReadOnly Property Kind As OperationKind Implements IOperation.Kind
                Get
168
                    Return OperationKind.SwitchCase
169 170 171 172 173
                End Get
            End Property

            Public ReadOnly Property Syntax As SyntaxNode Implements IOperation.Syntax
                Get
G
Gen Lu 已提交
174
                    Return _syntax
J
John Hamby 已提交
175 176 177
                End Get
            End Property

J
John Hamby 已提交
178 179 180 181 182 183 184 185 186 187 188 189
            Private ReadOnly Property IType As ITypeSymbol Implements IOperation.Type
                Get
                    Return Nothing
                End Get
            End Property

            Private ReadOnly Property IConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
                Get
                    Return New [Optional](Of Object)()
                End Get
            End Property

190
            Private NotInheritable Class CaseElse
G
Gen Lu 已提交
191 192
                Implements ISingleValueCaseClause

G
Gen Lu 已提交
193
                Private ReadOnly _boundCaseStatement As BoundCaseStatement
G
Gen Lu 已提交
194 195 196 197 198

                Public Sub New(boundCaseStatement As BoundCaseStatement)
                    _boundCaseStatement = boundCaseStatement
                End Sub

199
                Public Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
200 201 202
                    visitor.VisitSingleValueCaseClause(Me)
                End Sub

203
                Public Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
G
Gen Lu 已提交
204
                    Return visitor.VisitSingleValueCaseClause(Me, argument)
205 206
                End Function

G
Gen Lu 已提交
207 208 209 210 211 212
                Public ReadOnly Property Equality As BinaryOperationKind Implements ISingleValueCaseClause.Equality
                    Get
                        Return BinaryOperationKind.None
                    End Get
                End Property

J
John Hamby 已提交
213
                Public ReadOnly Property Value As IOperation Implements ISingleValueCaseClause.Value
G
Gen Lu 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                    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
                    End Get
                End Property
J
John Hamby 已提交
242 243 244 245 246 247 248 249 250 251 252 253

                Private ReadOnly Property IType As ITypeSymbol Implements IOperation.Type
                    Get
                        Return Nothing
                    End Get
                End Property

                Private ReadOnly Property IConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
                    Get
                        Return New [Optional](Of Object)()
                    End Get
                End Property
G
Gen Lu 已提交
254
            End Class
255

G
Gen Lu 已提交
256
        End Class
J
John Hamby 已提交
257 258
    End Class

C
CyrusNajmabadi 已提交
259
    Friend Partial Class BoundCaseBlock
G
Gen Lu 已提交
260 261 262
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function
263

264
        Public Overrides Sub Accept(visitor As OperationVisitor)
J
John Hamby 已提交
265
            visitor.VisitNoneOperation(Me)
266 267
        End Sub

268
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
J
John Hamby 已提交
269
            Return visitor.VisitNoneOperation(Me, argument)
270
        End Function
J
John Hamby 已提交
271 272
    End Class

C
CyrusNajmabadi 已提交
273
    Friend Partial Class BoundCaseClause
J
John Hamby 已提交
274 275
        Implements ICaseClause

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
        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
G
Gen Lu 已提交
291

292
        Public MustOverride Overloads Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
293

294
        Public MustOverride Overloads Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
J
John Hamby 已提交
295 296 297 298 299 300 301 302 303 304 305 306

        Private ReadOnly Property IType As ITypeSymbol Implements IOperation.Type
            Get
                Return Nothing
            End Get
        End Property

        Private ReadOnly Property IConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
            Get
                Return New [Optional](Of Object)()
            End Get
        End Property
J
John Hamby 已提交
307 308
    End Class

C
CyrusNajmabadi 已提交
309
    Friend Partial Class BoundSimpleCaseClause
J
John Hamby 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
        Implements ISingleValueCaseClause

        Private ReadOnly Property IEquality As BinaryOperationKind Implements ISingleValueCaseClause.Equality
            Get
                ' Can lifted operators appear here, and if so what is their correct treatment?
                Dim caseValue As BoundExpression = DirectCast(Me.IValue, BoundExpression)
                If caseValue IsNot Nothing Then
                    Select Case caseValue.Type.SpecialType
                        Case SpecialType.System_Int32, SpecialType.System_Int64, SpecialType.System_UInt32, SpecialType.System_UInt64, SpecialType.System_UInt16, SpecialType.System_Int16, SpecialType.System_SByte, SpecialType.System_Byte, SpecialType.System_Char
                            Return BinaryOperationKind.IntegerEquals

                        Case SpecialType.System_Boolean
                            Return BinaryOperationKind.BooleanEquals

                        Case SpecialType.System_String
                            Return BinaryOperationKind.StringEquals
                    End Select

                    If caseValue.Type.TypeKind = TypeKind.Enum Then
                        Return BinaryOperationKind.EnumEquals
                    End If
                End If

333
                Return BinaryOperationKind.Invalid
J
John Hamby 已提交
334 335 336
            End Get
        End Property

J
John Hamby 已提交
337
        Private ReadOnly Property IValue As IOperation Implements ISingleValueCaseClause.Value
J
John Hamby 已提交
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
            Get
                If Me.ValueOpt IsNot Nothing Then
                    Return Me.ValueOpt
                End If

                If Me.ConditionOpt IsNot Nothing AndAlso Me.ConditionOpt.Kind = BoundKind.BinaryOperator Then
                    Dim value As BoundBinaryOperator = DirectCast(Me.ConditionOpt, BoundBinaryOperator)
                    If value.OperatorKind = BinaryOperatorKind.Equals Then
                        Return value.Right
                    End If
                End If

                Return Nothing
            End Get
        End Property

354 355 356 357 358 359 360
        Protected Overrides ReadOnly Property IKind As OperationKind
            Get
                Return OperationKind.SingleValueCaseClause
            End Get
        End Property

        Protected Overrides ReadOnly Property ICaseKind As CaseKind
J
John Hamby 已提交
361
            Get
362
                Return CaseKind.SingleValue
J
John Hamby 已提交
363 364
            End Get
        End Property
G
Gen Lu 已提交
365

366
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
367 368
            visitor.VisitSingleValueCaseClause(Me)
        End Sub
369

370
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
371
            Return visitor.VisitSingleValueCaseClause(Me, argument)
372
        End Function
J
John Hamby 已提交
373 374
    End Class

C
CyrusNajmabadi 已提交
375
    Friend Partial Class BoundRangeCaseClause
J
John Hamby 已提交
376 377
        Implements IRangeCaseClause

J
John Hamby 已提交
378
        Private ReadOnly Property IMaximumValue As IOperation Implements IRangeCaseClause.MaximumValue
J
John Hamby 已提交
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
            Get
                If Me.UpperBoundOpt IsNot Nothing Then
                    Return Me.UpperBoundOpt
                End If

                If Me.UpperBoundConditionOpt.Kind = BoundKind.BinaryOperator Then
                    Dim upperBound As BoundBinaryOperator = DirectCast(Me.UpperBoundConditionOpt, BoundBinaryOperator)
                    If upperBound.OperatorKind = BinaryOperatorKind.LessThanOrEqual Then
                        Return upperBound.Right
                    End If
                End If

                Return Nothing
            End Get
        End Property

J
John Hamby 已提交
395
        Private ReadOnly Property IMinimumValue As IOperation Implements IRangeCaseClause.MinimumValue
J
John Hamby 已提交
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
            Get
                If Me.LowerBoundOpt IsNot Nothing Then
                    Return Me.LowerBoundOpt
                End If

                If Me.LowerBoundConditionOpt.Kind = BoundKind.BinaryOperator Then
                    Dim lowerBound As BoundBinaryOperator = DirectCast(Me.LowerBoundConditionOpt, BoundBinaryOperator)
                    If lowerBound.OperatorKind = BinaryOperatorKind.GreaterThanOrEqual Then
                        Return lowerBound.Right
                    End If
                End If

                Return Nothing
            End Get
        End Property

412 413 414 415 416 417 418
        Protected Overrides ReadOnly Property IKind As OperationKind
            Get
                Return OperationKind.RangeCaseClause
            End Get
        End Property

        Protected Overrides ReadOnly Property ICaseKind As CaseKind
J
John Hamby 已提交
419 420 421 422
            Get
                Return CaseKind.Range
            End Get
        End Property
G
Gen Lu 已提交
423

424
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
425 426
            visitor.VisitRangeCaseClause(Me)
        End Sub
427

428
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
429
            Return visitor.VisitRangeCaseClause(Me, argument)
430
        End Function
J
John Hamby 已提交
431 432
    End Class

C
CyrusNajmabadi 已提交
433
    Friend Partial Class BoundRelationalCaseClause
J
John Hamby 已提交
434 435 436 437 438 439 440 441
        Implements IRelationalCaseClause

        Private ReadOnly Property Relation As BinaryOperationKind Implements IRelationalCaseClause.Relation
            Get
                If Me.Value IsNot Nothing Then
                    Return DeriveBinaryOperationKind(Me.OperatorKind, DirectCast(Me.Value, BoundExpression))
                End If

442 443
                Return BinaryOperationKind.Invalid

J
John Hamby 已提交
444 445 446
            End Get
        End Property

J
John Hamby 已提交
447
        Private ReadOnly Property Value As IOperation Implements IRelationalCaseClause.Value
J
John Hamby 已提交
448 449 450 451 452 453 454 455 456 457 458 459 460
            Get
                If Me.OperandOpt IsNot Nothing Then
                    Return Me.OperandOpt
                End If

                If Me.ConditionOpt IsNot Nothing AndAlso Me.ConditionOpt.Kind = BoundKind.BinaryOperator Then
                    Return DirectCast(Me.ConditionOpt, BoundBinaryOperator).Right
                End If

                Return Nothing
            End Get
        End Property

461 462 463 464 465 466 467
        Protected Overrides ReadOnly Property IKind As OperationKind
            Get
                Return OperationKind.RelationalCaseClause
            End Get
        End Property

        Protected Overrides ReadOnly Property ICaseKind As CaseKind
J
John Hamby 已提交
468 469 470 471
            Get
                Return CaseKind.Relational
            End Get
        End Property
G
Gen Lu 已提交
472

473
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
474 475
            visitor.VisitRelationalCaseClause(Me)
        End Sub
476

477
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
478
            Return visitor.VisitRelationalCaseClause(Me, argument)
479
        End Function
J
John Hamby 已提交
480 481
    End Class

C
CyrusNajmabadi 已提交
482
    Friend Partial Class BoundCaseStatement
J
John Hamby 已提交
483 484 485 486 487

        ' Cases are found by going through ISwitch, so the VB Case statement is orphaned.
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function
488

489
        Public Overrides Sub Accept(visitor As OperationVisitor)
J
John Hamby 已提交
490
            visitor.VisitNoneOperation(Me)
491 492
        End Sub

493
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
J
John Hamby 已提交
494
            Return visitor.VisitNoneOperation(Me, argument)
495
        End Function
J
John Hamby 已提交
496 497
    End Class

C
CyrusNajmabadi 已提交
498
    Friend Partial Class BoundDoLoopStatement
J
John Hamby 已提交
499 500
        Implements IWhileUntilLoopStatement

J
John Hamby 已提交
501
        Private ReadOnly Property ICondition As IOperation Implements IForWhileUntilLoopStatement.Condition
J
John Hamby 已提交
502 503 504 505 506
            Get
                Return Me.ConditionOpt
            End Get
        End Property

507
        Private ReadOnly Property IBody As IOperation Implements ILoopStatement.Body
J
John Hamby 已提交
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
            Get
                Return Me.Body
            End Get
        End Property

        Private ReadOnly Property ILoopClass As LoopKind Implements ILoopStatement.LoopKind
            Get
                Return LoopKind.WhileUntil
            End Get
        End Property

        Private ReadOnly Property IIsTopTest As Boolean Implements IWhileUntilLoopStatement.IsTopTest
            Get
                Return Me.ConditionIsTop
            End Get
        End Property

        Private ReadOnly Property IIsWhile As Boolean Implements IWhileUntilLoopStatement.IsWhile
            Get
                Return Not Me.ConditionIsUntil
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.LoopStatement
        End Function

535
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
536 537
            visitor.VisitWhileUntilLoopStatement(Me)
        End Sub
538

539
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
540
            Return visitor.VisitWhileUntilLoopStatement(Me, argument)
541
        End Function
J
John Hamby 已提交
542 543
    End Class

C
CyrusNajmabadi 已提交
544
    Friend Partial Class BoundForToStatement
J
John Hamby 已提交
545 546
        Implements IForLoopStatement

G
Gen Lu 已提交
547
        Private Shared ReadOnly s_loopBottomMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, Object)
J
John Hamby 已提交
548

549
        Private ReadOnly Property IAtLoopBottom As ImmutableArray(Of IOperation) Implements IForLoopStatement.AtLoopBottom
J
John Hamby 已提交
550
            Get
G
Gen Lu 已提交
551
                Dim result = s_loopBottomMappings.GetValue(
J
John Hamby 已提交
552 553
                    Me,
                    Function(BoundFor)
554
                        Dim statements As ArrayBuilder(Of IOperation) = ArrayBuilder(Of IOperation).GetInstance()
J
John Hamby 已提交
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
                        Dim operators As BoundForToUserDefinedOperators = BoundFor.OperatorsOpt
                        If operators IsNot Nothing Then
                            ' Use the operator methods. Figure out the precise rules first.
                        Else
                            Dim controlReference As IReferenceExpression = TryCast(BoundFor.ControlVariable, IReferenceExpression)
                            If controlReference IsNot Nothing Then

                                ' ControlVariable += StepValue

                                Dim controlType As TypeSymbol = BoundFor.ControlVariable.Type

                                Dim stepValue As BoundExpression = BoundFor.StepValue
                                If stepValue Is Nothing Then
                                    stepValue = New BoundLiteral(Nothing, Semantics.Expression.SynthesizeNumeric(controlType, 1), controlType)
                                End If

J
John Hamby 已提交
571
                                Dim stepOperand As IOperation = If(stepValue.IsConstant, DirectCast(stepValue, IOperation), New Temporary(SyntheticLocalKind.ForLoopStepValue, BoundFor, stepValue))
J
John Hamby 已提交
572 573 574 575 576 577 578
                                statements.Add(New CompoundAssignment(controlReference, stepOperand, Semantics.Expression.DeriveAdditionKind(controlType), Nothing, stepValue.Syntax))
                            End If
                        End If

                        Return statements.ToImmutableAndFree()
                    End Function)

579
                Return DirectCast(result, ImmutableArray(Of IOperation))
J
John Hamby 已提交
580 581 582
            End Get
        End Property

G
Gen Lu 已提交
583
        Private Shared ReadOnly s_loopTopMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, Object)
J
John Hamby 已提交
584

585
        Private ReadOnly Property IBefore As ImmutableArray(Of IOperation) Implements IForLoopStatement.Before
J
John Hamby 已提交
586
            Get
G
Gen Lu 已提交
587
                Dim result = s_loopTopMappings.GetValue(
J
John Hamby 已提交
588 589
                    Me,
                    Function(BoundFor)
590
                        Dim statements As ArrayBuilder(Of IOperation) = ArrayBuilder(Of IOperation).GetInstance()
J
John Hamby 已提交
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

                        ' ControlVariable = InitialValue
                        Dim controlReference As IReferenceExpression = TryCast(BoundFor.ControlVariable, IReferenceExpression)
                        If controlReference IsNot Nothing Then
                            statements.Add(New Assignment(controlReference, BoundFor.InitialValue, BoundFor.InitialValue.Syntax))
                        End If

                        ' T0 = LimitValue
                        If Not Me.LimitValue.IsConstant Then
                            statements.Add(New Assignment(New Temporary(SyntheticLocalKind.ForLoopLimitValue, BoundFor, BoundFor.LimitValue), BoundFor.LimitValue, BoundFor.LimitValue.Syntax))
                        End If

                        ' T1 = StepValue
                        If BoundFor.StepValue IsNot Nothing AndAlso Not BoundFor.StepValue.IsConstant Then
                            statements.Add(New Assignment(New Temporary(SyntheticLocalKind.ForLoopStepValue, BoundFor, BoundFor.StepValue), BoundFor.StepValue, BoundFor.StepValue.Syntax))
                        End If

                        Return statements.ToImmutableAndFree()
                    End Function)

611
                Return DirectCast(result, ImmutableArray(Of IOperation))
J
John Hamby 已提交
612 613 614 615 616 617 618 619 620
            End Get
        End Property

        Private ReadOnly Property ILocals As ImmutableArray(Of ILocalSymbol) Implements IForLoopStatement.Locals
            Get
                Return ImmutableArray(Of ILocalSymbol).Empty
            End Get
        End Property

J
John Hamby 已提交
621
        Private Shared ReadOnly s_loopConditionMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, IOperation)
J
John Hamby 已提交
622

J
John Hamby 已提交
623
        Private ReadOnly Property ICondition As IOperation Implements IForWhileUntilLoopStatement.Condition
J
John Hamby 已提交
624
            Get
G
Gen Lu 已提交
625
                Return s_loopConditionMappings.GetValue(
J
John Hamby 已提交
626 627
                    Me,
                    Function(BoundFor)
J
John Hamby 已提交
628
                        Dim limitValue As IOperation = If(BoundFor.LimitValue.IsConstant, DirectCast(BoundFor.LimitValue, IOperation), New Temporary(SyntheticLocalKind.ForLoopLimitValue, BoundFor, BoundFor.LimitValue))
J
John Hamby 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
                        Dim controlVariable As BoundExpression = BoundFor.ControlVariable

                        Dim booleanType As ITypeSymbol = controlVariable.ExpressionSymbol.DeclaringCompilation.GetSpecialType(SpecialType.System_Boolean)

                        Dim operators As BoundForToUserDefinedOperators = Me.OperatorsOpt
                        If operators IsNot Nothing Then
                            ' Use the operator methods. Figure out the precise rules first.
                            Return Nothing
                        Else
                            If BoundFor.StepValue Is Nothing OrElse (BoundFor.StepValue.IsConstant AndAlso BoundFor.StepValue.ConstantValueOpt IsNot Nothing) Then
                                ' Either ControlVariable <= LimitValue or ControlVariable >= LimitValue, depending on whether the step value is negative.

                                Dim relationalCode As BinaryOperationKind = DeriveBinaryOperationKind(If(BoundFor.StepValue IsNot Nothing AndAlso BoundFor.StepValue.ConstantValueOpt.IsNegativeNumeric, BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThanOrEqual), controlVariable)
                                Return New Binary(relationalCode, controlVariable, limitValue, booleanType, limitValue.Syntax)
                            Else
                                ' If(StepValue >= 0, ControlVariable <= LimitValue, ControlVariable >= LimitValue)

J
John Hamby 已提交
646
                                Dim stepValue As IOperation = New Temporary(SyntheticLocalKind.ForLoopStepValue, BoundFor, BoundFor.StepValue)
J
John Hamby 已提交
647
                                Dim stepRelationalCode As BinaryOperationKind = DeriveBinaryOperationKind(BinaryOperatorKind.GreaterThanOrEqual, BoundFor.StepValue)
J
John Hamby 已提交
648
                                Dim stepCondition As IOperation = New Binary(stepRelationalCode, stepValue, New BoundLiteral(Nothing, Semantics.Expression.SynthesizeNumeric(stepValue.Type, 0), BoundFor.StepValue.Type), booleanType, BoundFor.StepValue.Syntax)
J
John Hamby 已提交
649 650

                                Dim positiveStepRelationalCode As BinaryOperationKind = DeriveBinaryOperationKind(BinaryOperatorKind.LessThanOrEqual, controlVariable)
J
John Hamby 已提交
651
                                Dim positiveStepCondition As IOperation = New Binary(positiveStepRelationalCode, controlVariable, limitValue, booleanType, limitValue.Syntax)
J
John Hamby 已提交
652 653

                                Dim negativeStepRelationalCode As BinaryOperationKind = DeriveBinaryOperationKind(BinaryOperatorKind.GreaterThanOrEqual, controlVariable)
J
John Hamby 已提交
654
                                Dim negativeStepCondition As IOperation = New Binary(negativeStepRelationalCode, controlVariable, limitValue, booleanType, limitValue.Syntax)
J
John Hamby 已提交
655 656 657 658 659 660 661 662

                                Return New ConditionalChoice(stepCondition, positiveStepCondition, negativeStepCondition, booleanType, limitValue.Syntax)
                            End If
                        End If
                    End Function)
            End Get
        End Property

663
        Private ReadOnly Property IBody As IOperation Implements ILoopStatement.Body
J
John Hamby 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
            Get
                Return Me.Body
            End Get
        End Property

        Private ReadOnly Property ILoopClass As LoopKind Implements ILoopStatement.LoopKind
            Get
                Return LoopKind.For
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.LoopStatement
        End Function

679
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
680 681 682
            visitor.VisitForLoopStatement(Me)
        End Sub

683
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
684
            Return visitor.VisitForLoopStatement(Me, argument)
685 686 687
        End Function

        Private NotInheritable Class Temporary
J
John Hamby 已提交
688 689 690
            Implements ISyntheticLocalReferenceExpression

            Private _temporaryKind As SyntheticLocalKind
691
            Private _containingStatement As IOperation
J
John Hamby 已提交
692
            Private _capturedValue As IOperation
J
John Hamby 已提交
693

J
John Hamby 已提交
694
            Public Sub New(temporaryKind As SyntheticLocalKind, containingStatement As IOperation, capturedValue As IOperation)
J
John Hamby 已提交
695 696 697 698 699
                Me._temporaryKind = temporaryKind
                Me._containingStatement = containingStatement
                Me._capturedValue = capturedValue
            End Sub

700
            Public Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
G
Gen Lu 已提交
701 702 703
                visitor.VisitSyntheticLocalReferenceExpression(Me)
            End Sub

704
            Public Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
G
Gen Lu 已提交
705
                Return visitor.VisitSyntheticLocalReferenceExpression(Me, argument)
706 707
            End Function

J
John Hamby 已提交
708
            Public ReadOnly Property ConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
J
John Hamby 已提交
709
                Get
710
                    Return New [Optional](Of Object)()
J
John Hamby 已提交
711 712 713 714 715 716 717 718 719
                End Get
            End Property

            Public ReadOnly Property Kind As OperationKind Implements IOperation.Kind
                Get
                    Return OperationKind.SyntheticLocalReferenceExpression
                End Get
            End Property

J
John Hamby 已提交
720
            Public ReadOnly Property IsInvalid As Boolean Implements IOperation.IsInvalid
721 722 723 724 725
                Get
                    Return False
                End Get
            End Property

J
John Hamby 已提交
726
            Public ReadOnly Property Type As ITypeSymbol Implements IOperation.Type
J
John Hamby 已提交
727
                Get
728
                    Return Me._capturedValue.Type
J
John Hamby 已提交
729 730 731
                End Get
            End Property

J
John Hamby 已提交
732
            Public ReadOnly Property Syntax As SyntaxNode Implements IOperation.Syntax
J
John Hamby 已提交
733 734 735 736 737
                Get
                    Return Me._capturedValue.Syntax
                End Get
            End Property

738
            Public ReadOnly Property ContainingStatement As IOperation Implements ISyntheticLocalReferenceExpression.ContainingStatement
J
John Hamby 已提交
739 740 741 742 743 744 745 746 747 748 749 750 751
                Get
                    Return Me._containingStatement
                End Get
            End Property

            Public ReadOnly Property SyntheticLocalKind As SyntheticLocalKind Implements ISyntheticLocalReferenceExpression.SyntheticLocalKind
                Get
                    Return Me._temporaryKind
                End Get
            End Property
        End Class
    End Class

C
CyrusNajmabadi 已提交
752
    Friend Partial Class BoundForEachStatement
J
John Hamby 已提交
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
        Implements IForEachLoopStatement

        Private ReadOnly Property IterationVariable As ILocalSymbol Implements IForEachLoopStatement.IterationVariable
            Get
                Dim controlReference As ILocalReferenceExpression = TryCast(Me.ControlVariable, ILocalReferenceExpression)
                If controlReference IsNot Nothing Then
                    Return controlReference.Local
                End If

                Return Nothing
            End Get
        End Property

        Private ReadOnly Property LoopClass As LoopKind Implements ILoopStatement.LoopKind
            Get
                Return LoopKind.ForEach
            End Get
        End Property

J
John Hamby 已提交
772
        Private ReadOnly Property IForEach_Collection As IOperation Implements IForEachLoopStatement.Collection
J
John Hamby 已提交
773 774 775 776 777
            Get
                Return Me.Collection
            End Get
        End Property

778
        Private ReadOnly Property ILoop_Body As IOperation Implements ILoopStatement.Body
J
John Hamby 已提交
779 780 781 782 783 784 785 786
            Get
                Return Me.Body
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.LoopStatement
        End Function
G
Gen Lu 已提交
787

788
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
789 790
            visitor.VisitForEachLoopStatement(Me)
        End Sub
791

792
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
793
            Return visitor.VisitForEachLoopStatement(Me, argument)
794
        End Function
J
John Hamby 已提交
795 796
    End Class

C
CyrusNajmabadi 已提交
797
    Friend Partial Class BoundTryStatement
J
John Hamby 已提交
798 799 800 801 802 803 804 805
        Implements ITryStatement

        Private ReadOnly Property IBody As IBlockStatement Implements ITryStatement.Body
            Get
                Return Me.TryBlock
            End Get
        End Property

806
        Private ReadOnly Property ICatches As ImmutableArray(Of ICatchClause) Implements ITryStatement.Catches
J
John Hamby 已提交
807
            Get
808
                Return Me.CatchBlocks.As(Of ICatchClause)()
J
John Hamby 已提交
809 810 811 812 813 814 815 816 817 818 819 820
            End Get
        End Property

        Private ReadOnly Property IFinallyHandler As IBlockStatement Implements ITryStatement.FinallyHandler
            Get
                Return Me.FinallyBlockOpt
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.TryStatement
        End Function
G
Gen Lu 已提交
821

822
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
823 824
            visitor.VisitTryStatement(Me)
        End Sub
825

826
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
827
            Return visitor.VisitTryStatement(Me, argument)
828
        End Function
J
John Hamby 已提交
829 830
    End Class

831 832
    Partial Friend Class BoundCatchBlock
        Implements ICatchClause
J
John Hamby 已提交
833

834
        Private ReadOnly Property ICaughtType As ITypeSymbol Implements ICatchClause.CaughtType
J
John Hamby 已提交
835 836 837 838 839 840 841 842 843 844
            Get
                If Me.ExceptionSourceOpt IsNot Nothing Then
                    Return Me.ExceptionSourceOpt.Type
                End If

                ' Ideally return System.Exception here is best, but without being able to get to a Compilation object, that's difficult.
                Return Nothing
            End Get
        End Property

J
John Hamby 已提交
845
        Private ReadOnly Property IFilter As IOperation Implements ICatchClause.Filter
J
John Hamby 已提交
846 847 848 849 850
            Get
                Return Me.ExceptionFilterOpt
            End Get
        End Property

851
        Private ReadOnly Property IHandler As IBlockStatement Implements ICatchClause.Handler
J
John Hamby 已提交
852 853 854 855 856
            Get
                Return Me.Body
            End Get
        End Property

857
        Private ReadOnly Property ILocals As ILocalSymbol Implements ICatchClause.ExceptionLocal
J
John Hamby 已提交
858 859 860 861 862 863 864
            Get
                Return Me.LocalOpt
            End Get
        End Property

        Private ReadOnly Property IKind As OperationKind Implements IOperation.Kind
            Get
865
                Return OperationKind.CatchClause
J
John Hamby 已提交
866 867 868
            End Get
        End Property

869
        Private ReadOnly Property IIsInvalid As Boolean Implements IOperation.IsInvalid
870 871 872 873 874
            Get
                Return Me.HasErrors
            End Get
        End Property

J
John Hamby 已提交
875 876 877 878 879
        Private ReadOnly Property ISyntax As SyntaxNode Implements IOperation.Syntax
            Get
                Return Me.Syntax
            End Get
        End Property
G
Gen Lu 已提交
880

J
John Hamby 已提交
881 882 883 884 885 886 887 888 889 890 891 892
        Private ReadOnly Property IType As ITypeSymbol Implements IOperation.Type
            Get
                Return Nothing
            End Get
        End Property

        Private ReadOnly Property IConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
            Get
                Return New [Optional](Of Object)()
            End Get
        End Property

893
        Public Overloads Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
G
Gen Lu 已提交
894 895
            visitor.VisitCatch(Me)
        End Sub
896

897
        Public Overloads Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
G
Gen Lu 已提交
898
            Return visitor.VisitCatch(Me, argument)
899
        End Function
J
John Hamby 已提交
900 901
    End Class

C
CyrusNajmabadi 已提交
902
    Friend Partial Class BoundBlock
J
John Hamby 已提交
903 904
        Implements IBlockStatement

905 906
        Private Shared ReadOnly s_blockStatementsMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundBlock, Object)

J
John Hamby 已提交
907 908 909 910 911 912
        Private ReadOnly Property ILocals As ImmutableArray(Of ILocalSymbol) Implements IBlockStatement.Locals
            Get
                Return Me.Locals.As(Of ILocalSymbol)()
            End Get
        End Property

913
        Private ReadOnly Property IStatements As ImmutableArray(Of IOperation) Implements IBlockStatement.Statements
J
John Hamby 已提交
914
            Get
G
Gen Lu 已提交
915
                ' This is to filter out operations of kind None.
916
                Dim statements = s_blockStatementsMappings.GetValue(Me, Function(boundBlock)
917
                                                                            Return boundBlock.Statements.As(Of IOperation).WhereAsArray(Function(statement)
918 919 920
                                                                                                                                            Return statement.Kind <> OperationKind.None
                                                                                                                                        End Function)
                                                                        End Function)
921
                Return DirectCast(statements, ImmutableArray(Of IOperation))
J
John Hamby 已提交
922 923 924 925 926 927
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.BlockStatement
        End Function
G
Gen Lu 已提交
928

929
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
930 931
            visitor.VisitBlockStatement(Me)
        End Sub
932

933
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
934
            Return visitor.VisitBlockStatement(Me, argument)
935
        End Function
J
John Hamby 已提交
936 937
    End Class

J
John Hamby 已提交
938
    Partial Friend Class BoundBadStatement
939
        Implements IInvalidStatement
J
John Hamby 已提交
940

J
John Hamby 已提交
941
        Protected Overrides Function StatementKind() As OperationKind
942
            Return OperationKind.InvalidStatement
J
John Hamby 已提交
943
        End Function
G
Gen Lu 已提交
944

945
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
946 947
            visitor.VisitInvalidStatement(Me)
        End Sub
948

949
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
950
            Return visitor.VisitInvalidStatement(Me, argument)
951
        End Function
J
John Hamby 已提交
952 953
    End Class

C
CyrusNajmabadi 已提交
954
    Friend Partial Class BoundReturnStatement
J
John Hamby 已提交
955 956
        Implements IReturnStatement

J
John Hamby 已提交
957
        Private ReadOnly Property IReturned As IOperation Implements IReturnStatement.ReturnedValue
J
John Hamby 已提交
958 959 960 961 962 963 964 965
            Get
                Return Me.ExpressionOpt
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.ReturnStatement
        End Function
G
Gen Lu 已提交
966

967
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
968 969
            visitor.VisitReturnStatement(Me)
        End Sub
970

971
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
972
            Return visitor.VisitReturnStatement(Me, argument)
973
        End Function
J
John Hamby 已提交
974 975
    End Class

C
CyrusNajmabadi 已提交
976
    Friend Partial Class BoundThrowStatement
J
John Hamby 已提交
977 978
        Implements IThrowStatement

J
John Hamby 已提交
979
        Private ReadOnly Property IThrown As IOperation Implements IThrowStatement.ThrownObject
J
John Hamby 已提交
980 981 982 983 984 985 986 987
            Get
                Return Me.ExpressionOpt
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.ThrowStatement
        End Function
G
Gen Lu 已提交
988

989
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
990 991
            visitor.VisitThrowStatement(Me)
        End Sub
992

993
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
994
            Return visitor.VisitThrowStatement(Me, argument)
995
        End Function
J
John Hamby 已提交
996 997
    End Class

C
CyrusNajmabadi 已提交
998
    Friend Partial Class BoundWhileStatement
J
John Hamby 已提交
999 1000
        Implements IWhileUntilLoopStatement

J
John Hamby 已提交
1001
        Private ReadOnly Property ICondition As IOperation Implements IForWhileUntilLoopStatement.Condition
J
John Hamby 已提交
1002 1003 1004 1005 1006
            Get
                Return Me.Condition
            End Get
        End Property

1007
        Private ReadOnly Property IBody As IOperation Implements ILoopStatement.Body
J
John Hamby 已提交
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
            Get
                Return Me.Body
            End Get
        End Property

        Private ReadOnly Property ILoopClass As LoopKind Implements ILoopStatement.LoopKind
            Get
                Return LoopKind.WhileUntil
            End Get
        End Property

        Private ReadOnly Property IIsTopTest As Boolean Implements IWhileUntilLoopStatement.IsTopTest
            Get
                Return True
            End Get
        End Property

        Private ReadOnly Property IIsWhile As Boolean Implements IWhileUntilLoopStatement.IsWhile
            Get
                Return True
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.LoopStatement
        End Function
G
Gen Lu 已提交
1034

1035
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1036 1037
            visitor.VisitWhileUntilLoopStatement(Me)
        End Sub
1038

1039
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1040
            Return visitor.VisitWhileUntilLoopStatement(Me, argument)
1041
        End Function
J
John Hamby 已提交
1042 1043
    End Class

C
CyrusNajmabadi 已提交
1044
    Friend Partial Class BoundDimStatement
J
John Hamby 已提交
1045 1046
        Implements IVariableDeclarationStatement

G
Gen Lu 已提交
1047
        Private Shared ReadOnly s_variablesMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundDimStatement, Object)
1048

1049
        Private ReadOnly Property IVariables As ImmutableArray(Of IVariableDeclaration) Implements IVariableDeclarationStatement.Variables
J
John Hamby 已提交
1050
            Get
G
Gen Lu 已提交
1051
                Dim variables = s_variablesMappings.GetValue(Me, Function(dimStatement)
1052
                                                                     Dim builder = ArrayBuilder(Of IVariableDeclaration).GetInstance()
G
Gen Lu 已提交
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
                                                                     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
1066
                                                               )
1067
                Return DirectCast(variables, ImmutableArray(Of IVariableDeclaration))
J
John Hamby 已提交
1068 1069 1070 1071 1072 1073
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.VariableDeclarationStatement
        End Function
G
Gen Lu 已提交
1074

1075
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1076 1077
            visitor.VisitVariableDeclarationStatement(Me)
        End Sub
1078

1079
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1080
            Return visitor.VisitVariableDeclarationStatement(Me, argument)
1081
        End Function
J
John Hamby 已提交
1082 1083
    End Class

C
CyrusNajmabadi 已提交
1084
    Friend Partial Class BoundYieldStatement
J
John Hamby 已提交
1085
        Implements IReturnStatement
J
John Hamby 已提交
1086
        Private ReadOnly Property IReturned As IOperation Implements IReturnStatement.ReturnedValue
J
John Hamby 已提交
1087 1088 1089 1090 1091 1092 1093 1094
            Get
                Return Me.Expression
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.YieldReturnStatement
        End Function
G
Gen Lu 已提交
1095

1096
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1097 1098
            visitor.VisitReturnStatement(Me)
        End Sub
1099

1100
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1101
            Return visitor.VisitReturnStatement(Me, argument)
1102
        End Function
J
John Hamby 已提交
1103 1104
    End Class

C
CyrusNajmabadi 已提交
1105
    Friend Partial Class BoundLabelStatement
J
John Hamby 已提交
1106 1107 1108 1109 1110 1111 1112 1113
        Implements ILabelStatement

        Private ReadOnly Property ILabel As ILabelSymbol Implements ILabelStatement.Label
            Get
                Return Me.Label
            End Get
        End Property

1114 1115 1116 1117 1118 1119 1120
        Private ReadOnly Property ILabeled As IOperation Implements ILabelStatement.LabeledStatement
            Get
                ' The VB bound trees do not encode the statement to which the label is attached.
                Return Nothing
            End Get
        End Property

J
John Hamby 已提交
1121 1122 1123
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.LabelStatement
        End Function
G
Gen Lu 已提交
1124

1125
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1126 1127
            visitor.VisitLabelStatement(Me)
        End Sub
1128

1129
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1130
            Return visitor.VisitLabelStatement(Me, argument)
1131
        End Function
J
John Hamby 已提交
1132 1133
    End Class

C
CyrusNajmabadi 已提交
1134
    Friend Partial Class BoundGotoStatement
J
John Hamby 已提交
1135 1136 1137 1138 1139 1140 1141 1142
        Implements IBranchStatement

        Private ReadOnly Property ITarget As ILabelSymbol Implements IBranchStatement.Target
            Get
                Return Me.Label
            End Get
        End Property

1143 1144 1145 1146 1147 1148
        Private ReadOnly Property IBranchKind As BranchKind Implements IBranchStatement.BranchKind
            Get
                Return BranchKind.GoTo
            End Get
        End Property

J
John Hamby 已提交
1149
        Protected Overrides Function StatementKind() As OperationKind
1150
            Return OperationKind.BranchStatement
J
John Hamby 已提交
1151
        End Function
G
Gen Lu 已提交
1152

1153
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1154 1155
            visitor.VisitBranchStatement(Me)
        End Sub
1156

1157
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1158
            Return visitor.VisitBranchStatement(Me, argument)
1159
        End Function
J
John Hamby 已提交
1160 1161
    End Class

C
CyrusNajmabadi 已提交
1162
    Friend Partial Class BoundContinueStatement
J
John Hamby 已提交
1163 1164 1165 1166 1167 1168 1169 1170
        Implements IBranchStatement

        Private ReadOnly Property ITarget As ILabelSymbol Implements IBranchStatement.Target
            Get
                Return Me.Label
            End Get
        End Property

1171 1172 1173 1174 1175 1176
        Private ReadOnly Property IBranchKind As BranchKind Implements IBranchStatement.BranchKind
            Get
                Return BranchKind.Continue
            End Get
        End Property

J
John Hamby 已提交
1177
        Protected Overrides Function StatementKind() As OperationKind
1178
            Return OperationKind.BranchStatement
J
John Hamby 已提交
1179
        End Function
G
Gen Lu 已提交
1180

1181
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1182 1183
            visitor.VisitBranchStatement(Me)
        End Sub
1184

1185
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1186
            Return visitor.VisitBranchStatement(Me, argument)
1187
        End Function
J
John Hamby 已提交
1188 1189
    End Class

C
CyrusNajmabadi 已提交
1190
    Friend Partial Class BoundExitStatement
J
John Hamby 已提交
1191 1192 1193 1194 1195 1196 1197 1198
        Implements IBranchStatement

        Private ReadOnly Property ITarget As ILabelSymbol Implements IBranchStatement.Target
            Get
                Return Me.Label
            End Get
        End Property

1199 1200 1201 1202 1203 1204
        Private ReadOnly Property IBranchKind As BranchKind Implements IBranchStatement.BranchKind
            Get
                Return BranchKind.Break
            End Get
        End Property

J
John Hamby 已提交
1205
        Protected Overrides Function StatementKind() As OperationKind
1206
            Return OperationKind.BranchStatement
J
John Hamby 已提交
1207
        End Function
G
Gen Lu 已提交
1208

1209
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1210 1211
            visitor.VisitBranchStatement(Me)
        End Sub
1212

1213
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1214
            Return visitor.VisitBranchStatement(Me, argument)
1215
        End Function
J
John Hamby 已提交
1216 1217
    End Class

C
CyrusNajmabadi 已提交
1218
    Friend Partial Class BoundSyncLockStatement
J
John Hamby 已提交
1219 1220
        Implements ILockStatement

J
John Hamby 已提交
1221
        Private ReadOnly Property ILocked As IOperation Implements ILockStatement.LockedObject
J
John Hamby 已提交
1222 1223 1224 1225 1226
            Get
                Return Me.LockExpression
            End Get
        End Property

1227
        Private ReadOnly Property IBody As IOperation Implements ILockStatement.Body
J
John Hamby 已提交
1228 1229 1230 1231 1232 1233 1234 1235
            Get
                Return Me.Body
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.LockStatement
        End Function
G
Gen Lu 已提交
1236

1237
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1238 1239
            visitor.VisitLockStatement(Me)
        End Sub
1240

1241
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1242
            Return visitor.VisitLockStatement(Me, argument)
1243
        End Function
J
John Hamby 已提交
1244 1245
    End Class

J
John Hamby 已提交
1246
    Partial Friend Class BoundNoOpStatement
1247 1248
        Implements IEmptyStatement

J
John Hamby 已提交
1249 1250 1251
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.EmptyStatement
        End Function
G
Gen Lu 已提交
1252

1253
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1254 1255
            visitor.VisitEmptyStatement(Me)
        End Sub
1256

1257
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1258
            Return visitor.VisitEmptyStatement(Me, argument)
1259
        End Function
J
John Hamby 已提交
1260 1261
    End Class

C
CyrusNajmabadi 已提交
1262
    Friend Partial Class BoundSequencePoint
J
John Hamby 已提交
1263 1264 1265
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function
1266

1267
        Public Overrides Sub Accept(visitor As OperationVisitor)
J
John Hamby 已提交
1268
            visitor.VisitNoneOperation(Me)
1269 1270
        End Sub

1271
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
J
John Hamby 已提交
1272
            Return visitor.VisitNoneOperation(Me, argument)
1273
        End Function
J
John Hamby 已提交
1274 1275
    End Class

C
CyrusNajmabadi 已提交
1276
    Friend Partial Class BoundSequencePointWithSpan
J
John Hamby 已提交
1277 1278 1279
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function
1280

1281
        Public Overrides Sub Accept(visitor As OperationVisitor)
J
John Hamby 已提交
1282
            visitor.VisitNoneOperation(Me)
1283 1284
        End Sub

1285
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
J
John Hamby 已提交
1286
            Return visitor.VisitNoneOperation(Me, argument)
1287
        End Function
J
John Hamby 已提交
1288 1289
    End Class

C
CyrusNajmabadi 已提交
1290
    Friend Partial Class BoundStateMachineScope
J
John Hamby 已提交
1291 1292 1293
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function
1294

1295
        Public Overrides Sub Accept(visitor As OperationVisitor)
J
John Hamby 已提交
1296
            visitor.VisitNoneOperation(Me)
1297 1298
        End Sub

1299
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
J
John Hamby 已提交
1300
            Return visitor.VisitNoneOperation(Me, argument)
1301
        End Function
J
John Hamby 已提交
1302 1303
    End Class

J
John Hamby 已提交
1304
    Partial Friend Class BoundStopStatement
1305 1306
        Implements IStopStatement

J
John Hamby 已提交
1307 1308 1309
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.StopStatement
        End Function
G
Gen Lu 已提交
1310

1311
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1312 1313
            visitor.VisitStopStatement(Me)
        End Sub
1314

1315
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1316
            Return visitor.VisitStopStatement(Me, argument)
1317
        End Function
J
John Hamby 已提交
1318 1319
    End Class

J
John Hamby 已提交
1320
    Partial Friend Class BoundEndStatement
1321 1322
        Implements IEndStatement

J
John Hamby 已提交
1323 1324 1325
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.EndStatement
        End Function
G
Gen Lu 已提交
1326

1327
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1328 1329
            visitor.VisitEndStatement(Me)
        End Sub
1330

1331
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1332
            Return visitor.VisitEndStatement(Me, argument)
1333
        End Function
J
John Hamby 已提交
1334 1335
    End Class

C
CyrusNajmabadi 已提交
1336
    Friend Partial Class BoundWithStatement
J
John Hamby 已提交
1337 1338
        Implements IWithStatement

1339
        Private ReadOnly Property IBody As IOperation Implements IWithStatement.Body
J
John Hamby 已提交
1340 1341 1342 1343 1344
            Get
                Return Me.Body
            End Get
        End Property

J
John Hamby 已提交
1345
        Private ReadOnly Property IValue As IOperation Implements IWithStatement.Value
J
John Hamby 已提交
1346 1347 1348 1349 1350 1351 1352 1353
            Get
                Return Me.OriginalExpression
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.WithStatement
        End Function
G
Gen Lu 已提交
1354

1355
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1356 1357
            visitor.VisitWithStatement(Me)
        End Sub
1358

1359
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1360
            Return visitor.VisitWithStatement(Me, argument)
1361
        End Function
J
John Hamby 已提交
1362 1363
    End Class

C
CyrusNajmabadi 已提交
1364
    Friend Partial Class BoundUsingStatement
J
John Hamby 已提交
1365 1366
        Implements IUsingWithExpressionStatement, IUsingWithDeclarationStatement

J
John Hamby 已提交
1367
        Private ReadOnly Property IValue As IOperation Implements IUsingWithExpressionStatement.Value
J
John Hamby 已提交
1368 1369 1370 1371 1372
            Get
                Return Me.ResourceExpressionOpt
            End Get
        End Property

G
Gen Lu 已提交
1373
        Private Shared ReadOnly s_variablesMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundUsingStatement, Variables)
J
John Hamby 已提交
1374

1375
        Private ReadOnly Property IVariables As IVariableDeclarationStatement Implements IUsingWithDeclarationStatement.Declaration
J
John Hamby 已提交
1376
            Get
G
Gen Lu 已提交
1377
                Return s_variablesMappings.GetValue(
J
John Hamby 已提交
1378 1379
                    Me,
                    Function(BoundUsing)
1380
                        Return New Variables(BoundUsing.ResourceList.As(Of IVariableDeclaration))
J
John Hamby 已提交
1381 1382 1383 1384
                    End Function)
            End Get
        End Property

1385
        Private ReadOnly Property IBody As IOperation Implements IUsingStatement.Body
J
John Hamby 已提交
1386 1387 1388 1389 1390 1391 1392 1393 1394
            Get
                Return Me.Body
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return If(Me._ResourceExpressionOpt Is Nothing, OperationKind.UsingWithDeclarationStatement, OperationKind.UsingWithExpressionStatement)
        End Function

1395
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1396 1397 1398 1399 1400 1401 1402
            If Me.StatementKind() = OperationKind.UsingWithDeclarationStatement Then
                visitor.VisitUsingWithDeclarationStatement(Me)
            Else
                visitor.VisitUsingWithExpressionStatement(Me)
            End If
        End Sub

1403
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1404
            If Me.StatementKind() = OperationKind.UsingWithDeclarationStatement Then
G
Gen Lu 已提交
1405
                Return visitor.VisitUsingWithDeclarationStatement(Me, argument)
1406
            Else
G
Gen Lu 已提交
1407
                Return visitor.VisitUsingWithExpressionStatement(Me, argument)
1408 1409 1410 1411
            End If
        End Function

        Private NotInheritable Class Variables
J
John Hamby 已提交
1412 1413
            Implements IVariableDeclarationStatement

1414
            Private ReadOnly _variables As ImmutableArray(Of IVariableDeclaration)
J
John Hamby 已提交
1415

1416
            Public Sub New(variables As ImmutableArray(Of IVariableDeclaration))
J
John Hamby 已提交
1417 1418 1419
                _variables = variables
            End Sub

1420
            Public Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
G
Gen Lu 已提交
1421 1422 1423
                visitor.VisitVariableDeclarationStatement(Me)
            End Sub

1424
            Public Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
G
Gen Lu 已提交
1425
                Return visitor.VisitVariableDeclarationStatement(Me, argument)
1426 1427
            End Function

J
John Hamby 已提交
1428 1429 1430 1431 1432 1433
            Public ReadOnly Property Kind As OperationKind Implements IOperation.Kind
                Get
                    Return OperationKind.VariableDeclarationStatement
                End Get
            End Property

1434
            Public ReadOnly Property IsInvalid As Boolean Implements IOperation.IsInvalid
1435 1436 1437 1438 1439
                Get
                    Return False
                End Get
            End Property

J
John Hamby 已提交
1440 1441 1442 1443 1444 1445
            Public ReadOnly Property Syntax As SyntaxNode Implements IOperation.Syntax
                Get
                    Return Nothing
                End Get
            End Property

1446
            Private ReadOnly Property IVariableDeclaration_Variables As ImmutableArray(Of IVariableDeclaration) Implements IVariableDeclarationStatement.Variables
J
John Hamby 已提交
1447 1448 1449 1450
                Get
                    Return _variables
                End Get
            End Property
J
John Hamby 已提交
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462

            Private ReadOnly Property IType As ITypeSymbol Implements IOperation.Type
                Get
                    Return Nothing
                End Get
            End Property

            Private ReadOnly Property IConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
                Get
                    Return New [Optional](Of Object)()
                End Get
            End Property
J
John Hamby 已提交
1463 1464 1465
        End Class
    End Class

C
CyrusNajmabadi 已提交
1466
    Friend Partial Class BoundExpressionStatement
J
John Hamby 已提交
1467 1468
        Implements IExpressionStatement

J
John Hamby 已提交
1469
        Private ReadOnly Property IOperation As IOperation Implements IExpressionStatement.Expression
J
John Hamby 已提交
1470 1471 1472 1473 1474 1475 1476 1477
            Get
                Return Me.Expression
            End Get
        End Property

        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.ExpressionStatement
        End Function
G
Gen Lu 已提交
1478

1479
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1480 1481
            visitor.VisitExpressionStatement(Me)
        End Sub
1482

1483
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1484
            Return visitor.VisitExpressionStatement(Me, argument)
1485
        End Function
J
John Hamby 已提交
1486
    End Class
J
John Hamby 已提交
1487

J
John Hamby 已提交
1488
    Partial Friend Class BoundAddRemoveHandlerStatement
1489
        Implements IExpressionStatement
J
John Hamby 已提交
1490

G
Gen Lu 已提交
1491
        Protected Shared ReadOnly s_expressionsMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundAddRemoveHandlerStatement, IEventAssignmentExpression)
J
John Hamby 已提交
1492

1493 1494 1495
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.ExpressionStatement
        End Function
J
John Hamby 已提交
1496

J
John Hamby 已提交
1497
        Protected MustOverride ReadOnly Property IOperation As IOperation Implements IExpressionStatement.Expression
J
John Hamby 已提交
1498

1499
        Public Overrides Sub Accept(visitor As OperationVisitor)
G
Gen Lu 已提交
1500 1501 1502
            visitor.VisitExpressionStatement(Me)
        End Sub

1503
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
G
Gen Lu 已提交
1504
            Return visitor.VisitExpressionStatement(Me, argument)
1505 1506 1507
        End Function

        Protected NotInheritable Class EventAssignmentExpression
1508
            Implements IEventAssignmentExpression
J
John Hamby 已提交
1509

1510 1511
            Private ReadOnly _statement As BoundAddRemoveHandlerStatement
            Private ReadOnly _adds As Boolean
J
John Hamby 已提交
1512

1513 1514 1515 1516
            Public Sub New(statement As BoundAddRemoveHandlerStatement, adds As Boolean)
                _statement = statement
                _adds = adds
            End Sub
J
John Hamby 已提交
1517

1518
            Public Sub Accept(visitor As OperationVisitor) Implements IOperation.Accept
G
Gen Lu 已提交
1519 1520 1521
                visitor.VisitEventAssignmentExpression(Me)
            End Sub

1522
            Public Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult Implements IOperation.Accept
G
Gen Lu 已提交
1523
                Return visitor.VisitEventAssignmentExpression(Me, argument)
1524 1525
            End Function

1526 1527 1528 1529 1530
            Public ReadOnly Property Adds As Boolean Implements IEventAssignmentExpression.Adds
                Get
                    Return _adds
                End Get
            End Property
J
John Hamby 已提交
1531

J
John Hamby 已提交
1532
            Public ReadOnly Property ConstantValue As [Optional](Of Object) Implements IOperation.ConstantValue
1533 1534 1535 1536
                Get
                    Return New [Optional](Of Object)()
                End Get
            End Property
J
John Hamby 已提交
1537

1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
            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

J
John Hamby 已提交
1549
            Public ReadOnly Property EventInstance As IOperation Implements IEventAssignmentExpression.EventInstance
1550
                Get
1551 1552 1553 1554
                    If [Event].IsStatic Then
                        Return Nothing
                    End If

1555 1556 1557 1558 1559 1560 1561 1562 1563
                    Dim eventAccess As BoundEventAccess = TryCast(_statement.EventAccess, BoundEventAccess)
                    If eventAccess IsNot Nothing Then
                        Return eventAccess.ReceiverOpt
                    End If

                    Return Nothing
                End Get
            End Property

J
John Hamby 已提交
1564
            Public ReadOnly Property HandlerValue As IOperation Implements IEventAssignmentExpression.HandlerValue
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
                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

J
John Hamby 已提交
1582
            Public ReadOnly Property Type As ITypeSymbol Implements IOperation.Type
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
                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
J
John Hamby 已提交
1594 1595
    End Class

J
John Hamby 已提交
1596
    Partial Friend Class BoundAddHandlerStatement
J
John Hamby 已提交
1597

J
John Hamby 已提交
1598
        Protected Overrides ReadOnly Property IOperation As IOperation
J
John Hamby 已提交
1599
            Get
G
Gen Lu 已提交
1600 1601 1602
                Return s_expressionsMappings.GetValue(Me, Function(statement)
                                                              Return New EventAssignmentExpression(statement, True)
                                                          End Function)
J
John Hamby 已提交
1603 1604 1605 1606
            End Get
        End Property
    End Class

J
John Hamby 已提交
1607
    Partial Friend Class BoundRemoveHandlerStatement
J
John Hamby 已提交
1608

J
John Hamby 已提交
1609
        Protected Overrides ReadOnly Property IOperation As IOperation
J
John Hamby 已提交
1610
            Get
G
Gen Lu 已提交
1611 1612 1613
                Return s_expressionsMappings.GetValue(Me, Function(statement)
                                                              Return New EventAssignmentExpression(statement, False)
                                                          End Function)
J
John Hamby 已提交
1614 1615 1616
            End Get
        End Property
    End Class
1617

J
John Hamby 已提交
1618
    Partial Friend Class BoundRedimStatement
1619 1620 1621 1622
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1623
        Public Overrides Sub Accept(visitor As OperationVisitor)
1624
            visitor.VisitNoneOperation(Me)
1625 1626
        End Sub

1627
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1628
            Return visitor.VisitNoneOperation(Me, argument)
1629 1630 1631
        End Function
    End Class

J
John Hamby 已提交
1632
    Partial Friend Class BoundRedimClause
1633 1634 1635 1636
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1637
        Public Overrides Sub Accept(visitor As OperationVisitor)
1638
            visitor.VisitNoneOperation(Me)
1639 1640
        End Sub

1641
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1642
            Return visitor.VisitNoneOperation(Me, argument)
1643 1644 1645
        End Function
    End Class

J
John Hamby 已提交
1646
    Partial Friend Class BoundEraseStatement
1647 1648 1649 1650
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1651
        Public Overrides Sub Accept(visitor As OperationVisitor)
1652
            visitor.VisitNoneOperation(Me)
1653 1654
        End Sub

1655
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1656
            Return visitor.VisitNoneOperation(Me, argument)
1657 1658 1659
        End Function
    End Class

J
John Hamby 已提交
1660
    Partial Friend Class BoundLocalDeclaration
1661 1662 1663 1664
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1665
        Public Overrides Sub Accept(visitor As OperationVisitor)
1666
            visitor.VisitNoneOperation(Me)
1667 1668
        End Sub

1669
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1670
            Return visitor.VisitNoneOperation(Me, argument)
1671 1672 1673
        End Function
    End Class

J
John Hamby 已提交
1674
    Partial Friend Class BoundAsNewLocalDeclarations
1675 1676 1677 1678
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1679
        Public Overrides Sub Accept(visitor As OperationVisitor)
1680
            visitor.VisitNoneOperation(Me)
1681 1682
        End Sub

1683
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1684
            Return visitor.VisitNoneOperation(Me, argument)
1685 1686 1687
        End Function
    End Class

J
John Hamby 已提交
1688
    Partial Friend Class BoundInitializer
1689 1690 1691 1692
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1693
        Public Overrides Sub Accept(visitor As OperationVisitor)
1694
            visitor.VisitNoneOperation(Me)
1695 1696
        End Sub

1697
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1698
            Return visitor.VisitNoneOperation(Me, argument)
1699 1700 1701
        End Function
    End Class

J
John Hamby 已提交
1702
    Partial Friend Class BoundConditionalGoto
1703 1704 1705 1706
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1707
        Public Overrides Sub Accept(visitor As OperationVisitor)
1708
            visitor.VisitNoneOperation(Me)
1709 1710
        End Sub

1711
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1712
            Return visitor.VisitNoneOperation(Me, argument)
1713 1714 1715
        End Function
    End Class

J
John Hamby 已提交
1716
    Partial Friend Class BoundStatementList
1717 1718 1719 1720
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1721
        Public Overrides Sub Accept(visitor As OperationVisitor)
1722
            visitor.VisitNoneOperation(Me)
1723 1724
        End Sub

1725
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1726
            Return visitor.VisitNoneOperation(Me, argument)
1727 1728 1729
        End Function
    End Class

J
John Hamby 已提交
1730
    Partial Friend Class BoundRaiseEventStatement
1731 1732
        Implements IExpressionStatement

J
John Hamby 已提交
1733
        Public ReadOnly Property Expression As IOperation Implements IExpressionStatement.Expression
1734 1735 1736 1737 1738
            Get
                Return Me.EventInvocation
            End Get
        End Property

1739
        Protected Overrides Function StatementKind() As OperationKind
1740
            Return OperationKind.ExpressionStatement
1741 1742
        End Function

1743
        Public Overrides Sub Accept(visitor As OperationVisitor)
1744
            visitor.VisitExpressionStatement(Me)
1745 1746
        End Sub

1747
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1748
            Return visitor.VisitExpressionStatement(Me, argument)
1749 1750 1751
        End Function
    End Class

C
CyrusNajmabadi 已提交
1752
    Friend Partial Class BoundResumeStatement
1753 1754 1755 1756
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1757
        Public Overrides Sub Accept(visitor As OperationVisitor)
1758
            visitor.VisitNoneOperation(Me)
1759 1760
        End Sub

1761
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1762
            Return visitor.VisitNoneOperation(Me, argument)
1763 1764 1765
        End Function
    End Class

C
CyrusNajmabadi 已提交
1766
    Friend Partial Class BoundOnErrorStatement
1767 1768 1769 1770
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1771
        Public Overrides Sub Accept(visitor As OperationVisitor)
1772
            visitor.VisitNoneOperation(Me)
1773 1774
        End Sub

1775
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1776
            Return visitor.VisitNoneOperation(Me, argument)
1777 1778 1779
        End Function
    End Class

C
CyrusNajmabadi 已提交
1780
    Friend Partial Class BoundUnstructuredExceptionHandlingStatement
1781 1782 1783 1784
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1785
        Public Overrides Sub Accept(visitor As OperationVisitor)
1786
            visitor.VisitNoneOperation(Me)
1787 1788
        End Sub

1789
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1790
            Return visitor.VisitNoneOperation(Me, argument)
1791 1792 1793
        End Function
    End Class

C
CyrusNajmabadi 已提交
1794
    Friend Partial Class BoundUnstructuredExceptionOnErrorSwitch
1795 1796 1797 1798
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1799
        Public Overrides Sub Accept(visitor As OperationVisitor)
1800
            visitor.VisitNoneOperation(Me)
1801 1802
        End Sub

1803
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1804
            Return visitor.VisitNoneOperation(Me, argument)
1805 1806 1807
        End Function
    End Class

C
CyrusNajmabadi 已提交
1808
    Friend Partial Class BoundUnstructuredExceptionResumeSwitch
1809 1810 1811 1812
        Protected Overrides Function StatementKind() As OperationKind
            Return OperationKind.None
        End Function

1813
        Public Overrides Sub Accept(visitor As OperationVisitor)
1814
            visitor.VisitNoneOperation(Me)
1815 1816
        End Sub

1817
        Public Overrides Function Accept(Of TArgument, TResult)(visitor As OperationVisitor(Of TArgument, TResult), argument As TArgument) As TResult
1818
            Return visitor.VisitNoneOperation(Me, argument)
1819 1820
        End Function
    End Class
J
John Hamby 已提交
1821
End Namespace