VisualBasicOperationFactory.vb 98.0 KB
Newer Older
1
' Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
H
Heejae Chang 已提交
2

3
Imports System.Collections.Concurrent
H
Heejae Chang 已提交
4
Imports System.Collections.Immutable
F
Fredric Silberberg 已提交
5
Imports Microsoft.CodeAnalysis.PooledObjects
H
Heejae Chang 已提交
6
Imports Microsoft.CodeAnalysis.VisualBasic
7
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
8
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
H
Heejae Chang 已提交
9 10 11

Namespace Microsoft.CodeAnalysis.Semantics
    Partial Friend NotInheritable Class VisualBasicOperationFactory
H
Heejae Chang 已提交
12

13 14
        Private ReadOnly _cache As ConcurrentDictionary(Of BoundNode, IOperation) =
            New ConcurrentDictionary(Of BoundNode, IOperation)(concurrencyLevel:=2, capacity:=10)
H
Heejae Chang 已提交
15

16 17 18 19 20 21
        Private ReadOnly _semanticModel As SemanticModel

        Public Sub New(semanticModel As SemanticModel)
            _semanticModel = semanticModel
        End Sub

22
        Public Function Create(boundNode As BoundNode) As IOperation
H
Heejae Chang 已提交
23 24 25 26
            If boundNode Is Nothing Then
                Return Nothing
            End If

H
Heejae Chang 已提交
27 28
            ' this should be removed once this issue is fixed
            ' https://github.com/dotnet/roslyn/issues/21186
29 30 31
            If TypeOf boundNode Is BoundValuePlaceholderBase Then
                ' since same place holder bound node appears in multiple places in the tree
                ' we can't use bound node to operation map.
32 33
                ' for now, we will just create new operation and return clone but we need to figure out
                ' what we want to do with place holder node such as just returning nothing
34
                Return _semanticModel.CloneOperation(CreateInternal(boundNode))
35 36
            End If

H
Heejae Chang 已提交
37 38
            ' this should be removed once this issue is fixed
            ' https://github.com/dotnet/roslyn/issues/21187
39 40 41 42 43 44 45
            If IsIgnoredNode(boundNode) Then
                ' due to how IOperation is set up, some of VB BoundNode must be ignored
                ' while generating IOperation. otherwise, 2 different IOperation trees will be created
                ' for nodes under same sub tree
                Return Nothing
            End If

F
Fredric Silberberg 已提交
46
            ' A BoundUserDefined conversion is always the operand of a BoundConversion, and is handled
47 48 49
            ' by the BoundConversion creation. We should never receive one in this top level create call.
            Debug.Assert(boundNode.Kind <> BoundKind.UserDefinedConversion)

50
            Return _cache.GetOrAdd(boundNode, Function(n) CreateInternal(n))
H
Heejae Chang 已提交
51 52
        End Function

H
Heejae Chang 已提交
53
        Private Shared Function IsIgnoredNode(boundNode As BoundNode) As Boolean
54
            ' since boundNode doesn't have parent pointer, it can't just look around using bound node
H
Heejae Chang 已提交
55 56
            ' it needs to use syntax node.  we ignore these because this will return its own operation tree
            ' that don't belong to its parent operation tree.
H
Heejae Chang 已提交
57
            Select Case boundNode.Kind
58 59 60
                Case BoundKind.LocalDeclaration
                    Return boundNode.Syntax.Kind() = SyntaxKind.ModifiedIdentifier AndAlso
                           If(boundNode.Syntax.Parent?.Kind() = SyntaxKind.VariableDeclarator, False)
H
Heejae Chang 已提交
61 62 63 64 65 66 67 68
                Case BoundKind.ExpressionStatement
                    Return boundNode.Syntax.Kind() = SyntaxKind.SelectStatement
                Case BoundKind.CaseBlock
                    Return True
                Case BoundKind.CaseStatement
                    Return True
                Case BoundKind.EventAccess
                    Return boundNode.Syntax.Parent.Kind() = SyntaxKind.AddHandlerStatement OrElse
69 70
                           boundNode.Syntax.Parent.Kind() = SyntaxKind.RemoveHandlerStatement OrElse
                           boundNode.Syntax.Parent.Kind() = SyntaxKind.RaiseEventAccessorStatement
H
Heejae Chang 已提交
71
            End Select
72 73 74 75

            Return False
        End Function

76
        Private Function CreateInternal(boundNode As BoundNode) As IOperation
H
Heejae Chang 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89
            Select Case boundNode.Kind
                Case BoundKind.AssignmentOperator
                    Return CreateBoundAssignmentOperatorOperation(DirectCast(boundNode, BoundAssignmentOperator))
                Case BoundKind.MeReference
                    Return CreateBoundMeReferenceOperation(DirectCast(boundNode, BoundMeReference))
                Case BoundKind.MyBaseReference
                    Return CreateBoundMyBaseReferenceOperation(DirectCast(boundNode, BoundMyBaseReference))
                Case BoundKind.MyClassReference
                    Return CreateBoundMyClassReferenceOperation(DirectCast(boundNode, BoundMyClassReference))
                Case BoundKind.Literal
                    Return CreateBoundLiteralOperation(DirectCast(boundNode, BoundLiteral))
                Case BoundKind.AwaitOperator
                    Return CreateBoundAwaitOperatorOperation(DirectCast(boundNode, BoundAwaitOperator))
90 91
                Case BoundKind.NameOfOperator
                    Return CreateBoundNameOfOperatorOperation(DirectCast(boundNode, BoundNameOfOperator))
H
Heejae Chang 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
                Case BoundKind.Lambda
                    Return CreateBoundLambdaOperation(DirectCast(boundNode, BoundLambda))
                Case BoundKind.Call
                    Return CreateBoundCallOperation(DirectCast(boundNode, BoundCall))
                Case BoundKind.OmittedArgument
                    Return CreateBoundOmittedArgumentOperation(DirectCast(boundNode, BoundOmittedArgument))
                Case BoundKind.Parenthesized
                    Return CreateBoundParenthesizedOperation(DirectCast(boundNode, BoundParenthesized))
                Case BoundKind.ArrayAccess
                    Return CreateBoundArrayAccessOperation(DirectCast(boundNode, BoundArrayAccess))
                Case BoundKind.UnaryOperator
                    Return CreateBoundUnaryOperatorOperation(DirectCast(boundNode, BoundUnaryOperator))
                Case BoundKind.UserDefinedUnaryOperator
                    Return CreateBoundUserDefinedUnaryOperatorOperation(DirectCast(boundNode, BoundUserDefinedUnaryOperator))
                Case BoundKind.BinaryOperator
                    Return CreateBoundBinaryOperatorOperation(DirectCast(boundNode, BoundBinaryOperator))
                Case BoundKind.UserDefinedBinaryOperator
                    Return CreateBoundUserDefinedBinaryOperatorOperation(DirectCast(boundNode, BoundUserDefinedBinaryOperator))
                Case BoundKind.BinaryConditionalExpression
                    Return CreateBoundBinaryConditionalExpressionOperation(DirectCast(boundNode, BoundBinaryConditionalExpression))
                Case BoundKind.UserDefinedShortCircuitingOperator
                    Return CreateBoundUserDefinedShortCircuitingOperatorOperation(DirectCast(boundNode, BoundUserDefinedShortCircuitingOperator))
                Case BoundKind.BadExpression
                    Return CreateBoundBadExpressionOperation(DirectCast(boundNode, BoundBadExpression))
                Case BoundKind.TryCast
                    Return CreateBoundTryCastOperation(DirectCast(boundNode, BoundTryCast))
                Case BoundKind.DirectCast
                    Return CreateBoundDirectCastOperation(DirectCast(boundNode, BoundDirectCast))
                Case BoundKind.Conversion
                    Return CreateBoundConversionOperation(DirectCast(boundNode, BoundConversion))
                Case BoundKind.TernaryConditionalExpression
                    Return CreateBoundTernaryConditionalExpressionOperation(DirectCast(boundNode, BoundTernaryConditionalExpression))
                Case BoundKind.TypeOf
                    Return CreateBoundTypeOfOperation(DirectCast(boundNode, BoundTypeOf))
                Case BoundKind.ObjectCreationExpression
                    Return CreateBoundObjectCreationExpressionOperation(DirectCast(boundNode, BoundObjectCreationExpression))
128 129 130 131
                Case BoundKind.ObjectInitializerExpression
                    Return CreateBoundObjectInitializerExpressionOperation(DirectCast(boundNode, BoundObjectInitializerExpression))
                Case BoundKind.CollectionInitializerExpression
                    Return CreateBoundCollectionInitializerExpressionOperation(DirectCast(boundNode, BoundCollectionInitializerExpression))
H
Heejae Chang 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
                Case BoundKind.NewT
                    Return CreateBoundNewTOperation(DirectCast(boundNode, BoundNewT))
                Case BoundKind.ArrayCreation
                    Return CreateBoundArrayCreationOperation(DirectCast(boundNode, BoundArrayCreation))
                Case BoundKind.ArrayInitialization
                    Return CreateBoundArrayInitializationOperation(DirectCast(boundNode, BoundArrayInitialization))
                Case BoundKind.PropertyAccess
                    Return CreateBoundPropertyAccessOperation(DirectCast(boundNode, BoundPropertyAccess))
                Case BoundKind.EventAccess
                    Return CreateBoundEventAccessOperation(DirectCast(boundNode, BoundEventAccess))
                Case BoundKind.FieldAccess
                    Return CreateBoundFieldAccessOperation(DirectCast(boundNode, BoundFieldAccess))
                Case BoundKind.ConditionalAccess
                    Return CreateBoundConditionalAccessOperation(DirectCast(boundNode, BoundConditionalAccess))
                Case BoundKind.ConditionalAccessReceiverPlaceholder
                    Return CreateBoundConditionalAccessReceiverPlaceholderOperation(DirectCast(boundNode, BoundConditionalAccessReceiverPlaceholder))
                Case BoundKind.Parameter
                    Return CreateBoundParameterOperation(DirectCast(boundNode, BoundParameter))
                Case BoundKind.Local
                    Return CreateBoundLocalOperation(DirectCast(boundNode, BoundLocal))
152 153
                Case BoundKind.LateInvocation
                    Return CreateBoundLateInvocationOperation(DirectCast(boundNode, BoundLateInvocation))
H
Heejae Chang 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
                Case BoundKind.LateMemberAccess
                    Return CreateBoundLateMemberAccessOperation(DirectCast(boundNode, BoundLateMemberAccess))
                Case BoundKind.FieldInitializer
                    Return CreateBoundFieldInitializerOperation(DirectCast(boundNode, BoundFieldInitializer))
                Case BoundKind.PropertyInitializer
                    Return CreateBoundPropertyInitializerOperation(DirectCast(boundNode, BoundPropertyInitializer))
                Case BoundKind.ParameterEqualsValue
                    Return CreateBoundParameterEqualsValueOperation(DirectCast(boundNode, BoundParameterEqualsValue))
                Case BoundKind.RValuePlaceholder
                    Return CreateBoundRValuePlaceholderOperation(DirectCast(boundNode, BoundRValuePlaceholder))
                Case BoundKind.IfStatement
                    Return CreateBoundIfStatementOperation(DirectCast(boundNode, BoundIfStatement))
                Case BoundKind.SelectStatement
                    Return CreateBoundSelectStatementOperation(DirectCast(boundNode, BoundSelectStatement))
                Case BoundKind.SimpleCaseClause
                    Return CreateBoundSimpleCaseClauseOperation(DirectCast(boundNode, BoundSimpleCaseClause))
                Case BoundKind.RangeCaseClause
                    Return CreateBoundRangeCaseClauseOperation(DirectCast(boundNode, BoundRangeCaseClause))
                Case BoundKind.RelationalCaseClause
                    Return CreateBoundRelationalCaseClauseOperation(DirectCast(boundNode, BoundRelationalCaseClause))
                Case BoundKind.DoLoopStatement
                    Return CreateBoundDoLoopStatementOperation(DirectCast(boundNode, BoundDoLoopStatement))
                Case BoundKind.ForToStatement
                    Return CreateBoundForToStatementOperation(DirectCast(boundNode, BoundForToStatement))
                Case BoundKind.ForEachStatement
                    Return CreateBoundForEachStatementOperation(DirectCast(boundNode, BoundForEachStatement))
                Case BoundKind.TryStatement
                    Return CreateBoundTryStatementOperation(DirectCast(boundNode, BoundTryStatement))
                Case BoundKind.CatchBlock
                    Return CreateBoundCatchBlockOperation(DirectCast(boundNode, BoundCatchBlock))
                Case BoundKind.Block
                    Return CreateBoundBlockOperation(DirectCast(boundNode, BoundBlock))
                Case BoundKind.BadStatement
                    Return CreateBoundBadStatementOperation(DirectCast(boundNode, BoundBadStatement))
                Case BoundKind.ReturnStatement
                    Return CreateBoundReturnStatementOperation(DirectCast(boundNode, BoundReturnStatement))
                Case BoundKind.ThrowStatement
                    Return CreateBoundThrowStatementOperation(DirectCast(boundNode, BoundThrowStatement))
                Case BoundKind.WhileStatement
                    Return CreateBoundWhileStatementOperation(DirectCast(boundNode, BoundWhileStatement))
                Case BoundKind.DimStatement
                    Return CreateBoundDimStatementOperation(DirectCast(boundNode, BoundDimStatement))
                Case BoundKind.YieldStatement
                    Return CreateBoundYieldStatementOperation(DirectCast(boundNode, BoundYieldStatement))
                Case BoundKind.LabelStatement
                    Return CreateBoundLabelStatementOperation(DirectCast(boundNode, BoundLabelStatement))
                Case BoundKind.GotoStatement
                    Return CreateBoundGotoStatementOperation(DirectCast(boundNode, BoundGotoStatement))
                Case BoundKind.ContinueStatement
                    Return CreateBoundContinueStatementOperation(DirectCast(boundNode, BoundContinueStatement))
                Case BoundKind.ExitStatement
                    Return CreateBoundExitStatementOperation(DirectCast(boundNode, BoundExitStatement))
                Case BoundKind.SyncLockStatement
                    Return CreateBoundSyncLockStatementOperation(DirectCast(boundNode, BoundSyncLockStatement))
                Case BoundKind.NoOpStatement
                    Return CreateBoundNoOpStatementOperation(DirectCast(boundNode, BoundNoOpStatement))
                Case BoundKind.StopStatement
                    Return CreateBoundStopStatementOperation(DirectCast(boundNode, BoundStopStatement))
                Case BoundKind.EndStatement
                    Return CreateBoundEndStatementOperation(DirectCast(boundNode, BoundEndStatement))
                Case BoundKind.WithStatement
                    Return CreateBoundWithStatementOperation(DirectCast(boundNode, BoundWithStatement))
                Case BoundKind.UsingStatement
                    Return CreateBoundUsingStatementOperation(DirectCast(boundNode, BoundUsingStatement))
                Case BoundKind.ExpressionStatement
                    Return CreateBoundExpressionStatementOperation(DirectCast(boundNode, BoundExpressionStatement))
                Case BoundKind.RaiseEventStatement
                    Return CreateBoundRaiseEventStatementOperation(DirectCast(boundNode, BoundRaiseEventStatement))
                Case BoundKind.AddHandlerStatement
                    Return CreateBoundAddHandlerStatementOperation(DirectCast(boundNode, BoundAddHandlerStatement))
                Case BoundKind.RemoveHandlerStatement
                    Return CreateBoundRemoveHandlerStatementOperation(DirectCast(boundNode, BoundRemoveHandlerStatement))
226 227
                Case BoundKind.TupleLiteral,
                     BoundKind.ConvertedTupleLiteral
228
                    Return CreateBoundTupleExpressionOperation(DirectCast(boundNode, BoundTupleExpression))
229 230 231
                Case BoundKind.InterpolatedStringExpression
                    Return CreateBoundInterpolatedStringExpressionOperation(DirectCast(boundNode, BoundInterpolatedStringExpression))
                Case BoundKind.Interpolation
M
Manish Vasani 已提交
232
                    Return CreateBoundInterpolationOperation(DirectCast(boundNode, BoundInterpolation))
233 234 235 236 237 238
                Case BoundKind.AnonymousTypeCreationExpression
                    Return CreateBoundAnonymousTypeCreationExpressionOperation(DirectCast(boundNode, BoundAnonymousTypeCreationExpression))
                Case BoundKind.AnonymousTypeFieldInitializer
                    Return Create(DirectCast(boundNode, BoundAnonymousTypeFieldInitializer).Value)
                Case BoundKind.AnonymousTypePropertyAccess
                    Return CreateBoundAnonymousTypePropertyAccessOperation(DirectCast(boundNode, BoundAnonymousTypePropertyAccess))
H
Heejae Chang 已提交
239
                Case Else
240
                    Dim constantValue = ConvertToOptional(TryCast(boundNode, BoundExpression)?.ConstantValueOpt)
J
jinuz420 已提交
241 242
                    Dim isImplicit As Boolean = boundNode.WasCompilerGenerated
                    Return Operation.CreateOperationNone(_semanticModel, boundNode.Syntax, constantValue, Function() GetIOperationChildren(boundNode), isImplicit)
H
Heejae Chang 已提交
243 244
            End Select
        End Function
H
Heejae Chang 已提交
245

246
        Private Function GetIOperationChildren(boundNode As BoundNode) As ImmutableArray(Of IOperation)
247 248 249 250 251 252 253 254 255 256 257 258 259 260
            Dim boundNodeWithChildren = DirectCast(boundNode, IBoundNodeWithIOperationChildren)
            If boundNodeWithChildren.Children.IsDefaultOrEmpty Then
                Return ImmutableArray(Of IOperation).Empty
            End If

            Dim builder = ArrayBuilder(Of IOperation).GetInstance(boundNodeWithChildren.Children.Length)
            For Each childNode In boundNodeWithChildren.Children
                Dim operation = Create(childNode)
                builder.Add(operation)
            Next

            Return builder.ToImmutableAndFree()
        End Function

261
        Private Function CreateBoundAssignmentOperatorOperation(boundAssignmentOperator As BoundAssignmentOperator) As IOperation
H
Heejae Chang 已提交
262
            Dim kind = GetAssignmentKind(boundAssignmentOperator)
J
jinuz420 已提交
263
            Dim isImplicit As Boolean = boundAssignmentOperator.WasCompilerGenerated
H
Heejae Chang 已提交
264
            If kind = OperationKind.CompoundAssignmentExpression Then
265 266 267
                ' convert Right to IOperation temporarily. we do this to get right operand, operator method and etc
                Dim temporaryRight = DirectCast(Create(boundAssignmentOperator.Right), IBinaryOperatorExpression)

268
                Dim operatorKind As BinaryOperatorKind = temporaryRight.OperatorKind
H
Heejae Chang 已提交
269
                Dim target As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundAssignmentOperator.Left))
270 271 272 273 274 275 276 277

                ' right now, parent of right operand is set to the temporary IOperation, reset the parent
                ' we basically need to do this since we skip BoundAssignmentOperator.Right from IOperation tree
                Dim rightOperand = Operation.ResetParentOperation(temporaryRight.RightOperand)
                Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() rightOperand)

                Dim usesOperatorMethod As Boolean = temporaryRight.UsesOperatorMethod
                Dim operatorMethod As IMethodSymbol = temporaryRight.OperatorMethod
H
Heejae Chang 已提交
278 279 280
                Dim syntax As SyntaxNode = boundAssignmentOperator.Syntax
                Dim type As ITypeSymbol = boundAssignmentOperator.Type
                Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAssignmentOperator.ConstantValueOpt)
M
Manish Vasani 已提交
281
                Dim isLifted As Boolean = boundAssignmentOperator.Type.IsNullableType()
282
                Dim isChecked As Boolean = temporaryRight.IsChecked
283
                Return New LazyCompoundAssignmentExpression(operatorKind, isLifted, isChecked, target, value, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
284
            Else
H
Heejae Chang 已提交
285 286
                Dim target As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundAssignmentOperator.Left))
                Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundAssignmentOperator.Right))
H
Heejae Chang 已提交
287 288 289
                Dim syntax As SyntaxNode = boundAssignmentOperator.Syntax
                Dim type As ITypeSymbol = boundAssignmentOperator.Type
                Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAssignmentOperator.ConstantValueOpt)
J
jinuz420 已提交
290
                Return New LazySimpleAssignmentExpression(target, value, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
291 292
            End If
        End Function
H
Heejae Chang 已提交
293

294
        Private Function CreateBoundMeReferenceOperation(boundMeReference As BoundMeReference) As IInstanceReferenceExpression
H
Heejae Chang 已提交
295 296 297
            Dim syntax As SyntaxNode = boundMeReference.Syntax
            Dim type As ITypeSymbol = boundMeReference.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundMeReference.ConstantValueOpt)
J
jinuz420 已提交
298
            Dim isImplicit As Boolean = boundMeReference.WasCompilerGenerated
299
            Return New InstanceReferenceExpression(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
300
        End Function
H
Heejae Chang 已提交
301

302
        Private Function CreateBoundMyBaseReferenceOperation(boundMyBaseReference As BoundMyBaseReference) As IInstanceReferenceExpression
H
Heejae Chang 已提交
303 304 305
            Dim syntax As SyntaxNode = boundMyBaseReference.Syntax
            Dim type As ITypeSymbol = boundMyBaseReference.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundMyBaseReference.ConstantValueOpt)
J
jinuz420 已提交
306
            Dim isImplicit As Boolean = boundMyBaseReference.WasCompilerGenerated
307
            Return New InstanceReferenceExpression(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
308
        End Function
H
Heejae Chang 已提交
309

310
        Private Function CreateBoundMyClassReferenceOperation(boundMyClassReference As BoundMyClassReference) As IInstanceReferenceExpression
H
Heejae Chang 已提交
311 312 313
            Dim syntax As SyntaxNode = boundMyClassReference.Syntax
            Dim type As ITypeSymbol = boundMyClassReference.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundMyClassReference.ConstantValueOpt)
J
jinuz420 已提交
314
            Dim isImplicit As Boolean = boundMyClassReference.WasCompilerGenerated
315
            Return New InstanceReferenceExpression(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
316
        End Function
H
Heejae Chang 已提交
317

318
        Private Function CreateBoundLiteralOperation(boundLiteral As BoundLiteral) As ILiteralExpression
H
Heejae Chang 已提交
319 320 321
            Dim syntax As SyntaxNode = boundLiteral.Syntax
            Dim type As ITypeSymbol = boundLiteral.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLiteral.ConstantValueOpt)
J
jinuz420 已提交
322
            Dim isImplicit As Boolean = boundLiteral.WasCompilerGenerated
323
            Return New LiteralExpression(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
324
        End Function
H
Heejae Chang 已提交
325

326
        Private Function CreateBoundAwaitOperatorOperation(boundAwaitOperator As BoundAwaitOperator) As IAwaitExpression
H
Heejae Chang 已提交
327
            Dim awaitedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundAwaitOperator.Operand))
H
Heejae Chang 已提交
328 329 330
            Dim syntax As SyntaxNode = boundAwaitOperator.Syntax
            Dim type As ITypeSymbol = boundAwaitOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAwaitOperator.ConstantValueOpt)
J
jinuz420 已提交
331 332
            Dim isImplicit As Boolean = boundAwaitOperator.WasCompilerGenerated
            Return New LazyAwaitExpression(awaitedValue, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
333
        End Function
H
Heejae Chang 已提交
334

335 336 337 338 339
        Private Function CreateBoundNameOfOperatorOperation(boundNameOfOperator As BoundNameOfOperator) As INameOfExpression
            Dim argument As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundNameOfOperator.Argument))
            Dim syntax As SyntaxNode = boundNameOfOperator.Syntax
            Dim type As ITypeSymbol = boundNameOfOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundNameOfOperator.ConstantValueOpt)
J
jinuz420 已提交
340 341
            Dim isImplicit As Boolean = boundNameOfOperator.WasCompilerGenerated
            Return New LazyNameOfExpression(argument, _semanticModel, syntax, type, constantValue, isImplicit)
342 343
        End Function

344 345
        Private Function CreateBoundLambdaOperation(boundLambda As BoundLambda) As IAnonymousFunctionExpression
            Dim symbol As IMethodSymbol = boundLambda.LambdaSymbol
H
Heejae Chang 已提交
346 347 348 349
            Dim body As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundLambda.Body), IBlockStatement))
            Dim syntax As SyntaxNode = boundLambda.Syntax
            Dim type As ITypeSymbol = boundLambda.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLambda.ConstantValueOpt)
J
jinuz420 已提交
350
            Dim isImplicit As Boolean = boundLambda.WasCompilerGenerated
351
            Return New LazyAnonymousFunctionExpression(symbol, body, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
352
        End Function
H
Heejae Chang 已提交
353

354
        Private Function CreateBoundCallOperation(boundCall As BoundCall) As IInvocationExpression
H
Heejae Chang 已提交
355
            Dim targetMethod As IMethodSymbol = boundCall.Method
H
Heejae Chang 已提交
356
            Dim receiver As IOperation = Create(boundCall.ReceiverOpt)
H
Heejae Chang 已提交
357

358 359 360 361 362 363 364 365 366 367 368 369 370
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() If(targetMethod.IsShared, Nothing, receiver))
            Dim isVirtual As Boolean =
                targetMethod IsNot Nothing AndAlso
                instance IsNot Nothing AndAlso
                (targetMethod.IsVirtual OrElse targetMethod.IsAbstract OrElse targetMethod.IsOverride) AndAlso
                receiver.Kind <> BoundKind.MyBaseReference AndAlso
                receiver.Kind <> BoundKind.MyClassReference

            Dim argumentsInEvaluationOrder As Lazy(Of ImmutableArray(Of IArgument)) = New Lazy(Of ImmutableArray(Of IArgument))(
                Function()
                    Return DeriveArguments(boundCall.Arguments, boundCall.Method.Parameters)
                End Function)

H
Heejae Chang 已提交
371 372 373
            Dim syntax As SyntaxNode = boundCall.Syntax
            Dim type As ITypeSymbol = boundCall.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundCall.ConstantValueOpt)
J
jinuz420 已提交
374 375
            Dim isImplicit As Boolean = boundCall.WasCompilerGenerated
            Return New LazyInvocationExpression(targetMethod, instance, isVirtual, argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
376
        End Function
H
Heejae Chang 已提交
377

378
        Private Function CreateBoundOmittedArgumentOperation(boundOmittedArgument As BoundOmittedArgument) As IOmittedArgumentExpression
H
Heejae Chang 已提交
379 380 381
            Dim syntax As SyntaxNode = boundOmittedArgument.Syntax
            Dim type As ITypeSymbol = boundOmittedArgument.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundOmittedArgument.ConstantValueOpt)
J
jinuz420 已提交
382 383
            Dim isImplicit As Boolean = boundOmittedArgument.WasCompilerGenerated
            Return New OmittedArgumentExpression(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
384
        End Function
H
Heejae Chang 已提交
385

386
        Private Function CreateBoundParenthesizedOperation(boundParenthesized As BoundParenthesized) As IParenthesizedExpression
H
Heejae Chang 已提交
387
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundParenthesized.Expression))
H
Heejae Chang 已提交
388 389 390
            Dim syntax As SyntaxNode = boundParenthesized.Syntax
            Dim type As ITypeSymbol = boundParenthesized.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundParenthesized.ConstantValueOpt)
J
jinuz420 已提交
391 392
            Dim isImplicit As Boolean = boundParenthesized.WasCompilerGenerated
            Return New LazyParenthesizedExpression(operand, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
393
        End Function
H
Heejae Chang 已提交
394

395
        Private Function CreateBoundArrayAccessOperation(boundArrayAccess As BoundArrayAccess) As IArrayElementReferenceExpression
H
Heejae Chang 已提交
396
            Dim arrayReference As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundArrayAccess.Expression))
H
Heejae Chang 已提交
397 398 399 400
            Dim indices As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundArrayAccess.Indices.SelectAsArray(Function(n) DirectCast(Create(n), IOperation)))
            Dim syntax As SyntaxNode = boundArrayAccess.Syntax
            Dim type As ITypeSymbol = boundArrayAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundArrayAccess.ConstantValueOpt)
J
jinuz420 已提交
401 402
            Dim isImplicit As Boolean = boundArrayAccess.WasCompilerGenerated
            Return New LazyArrayElementReferenceExpression(arrayReference, indices, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
403
        End Function
H
Heejae Chang 已提交
404

405
        Private Function CreateBoundUnaryOperatorOperation(boundUnaryOperator As BoundUnaryOperator) As IUnaryOperatorExpression
406
            Dim operatorKind As UnaryOperatorKind = Helper.DeriveUnaryOperatorKind(boundUnaryOperator.OperatorKind)
H
Heejae Chang 已提交
407
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUnaryOperator.Operand))
H
Heejae Chang 已提交
408 409 410 411 412
            Dim usesOperatorMethod As Boolean = False
            Dim operatorMethod As IMethodSymbol = Nothing
            Dim syntax As SyntaxNode = boundUnaryOperator.Syntax
            Dim type As ITypeSymbol = boundUnaryOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundUnaryOperator.ConstantValueOpt)
M
Manish Vasani 已提交
413 414
            Dim isLifted As Boolean = (boundUnaryOperator.OperatorKind And VisualBasic.UnaryOperatorKind.Lifted) <> 0
            Dim isChecked As Boolean = boundUnaryOperator.Checked
J
jinuz420 已提交
415
            Dim isImplicit As Boolean = boundUnaryOperator.WasCompilerGenerated
416
            Return New LazyUnaryOperatorExpression(operatorKind, operand, isLifted, isChecked, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
417
        End Function
H
Heejae Chang 已提交
418

419
        Private Function CreateBoundUserDefinedUnaryOperatorOperation(boundUserDefinedUnaryOperator As BoundUserDefinedUnaryOperator) As IUnaryOperatorExpression
420
            Dim operatorKind As UnaryOperatorKind = Helper.DeriveUnaryOperatorKind(boundUserDefinedUnaryOperator.OperatorKind)
H
Heejae Chang 已提交
421 422 423 424 425 426 427 428 429 430 431 432
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function()
                                                                             If boundUserDefinedUnaryOperator.UnderlyingExpression.Kind = BoundKind.Call Then
                                                                                 Return Create(boundUserDefinedUnaryOperator.Operand)
                                                                             Else
                                                                                 Return GetChildOfBadExpression(boundUserDefinedUnaryOperator.UnderlyingExpression, 0)
                                                                             End If
                                                                         End Function)
            Dim operatorMethod As IMethodSymbol = If(boundUserDefinedUnaryOperator.UnderlyingExpression.Kind = BoundKind.Call, boundUserDefinedUnaryOperator.Call.Method, Nothing)
            Dim usesOperatorMethod As Boolean = operatorMethod IsNot Nothing
            Dim syntax As SyntaxNode = boundUserDefinedUnaryOperator.Syntax
            Dim type As ITypeSymbol = boundUserDefinedUnaryOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundUserDefinedUnaryOperator.ConstantValueOpt)
M
Manish Vasani 已提交
433 434
            Dim isLifted As Boolean = (boundUserDefinedUnaryOperator.OperatorKind And VisualBasic.UnaryOperatorKind.Lifted) <> 0
            Dim isChecked As Boolean = False
J
jinuz420 已提交
435
            Dim isImplicit As Boolean = boundUserDefinedUnaryOperator.WasCompilerGenerated
436
            Return New LazyUnaryOperatorExpression(operatorKind, operand, isLifted, isChecked, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
437
        End Function
H
Heejae Chang 已提交
438

439
        Private Function CreateBoundBinaryOperatorOperation(boundBinaryOperator As BoundBinaryOperator) As IBinaryOperatorExpression
M
Manish Vasani 已提交
440
            Dim operatorKind As BinaryOperatorKind = Helper.DeriveBinaryOperatorKind(boundBinaryOperator.OperatorKind, boundBinaryOperator.Left)
H
Heejae Chang 已提交
441 442
            Dim leftOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryOperator.Left))
            Dim rightOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryOperator.Right))
H
Heejae Chang 已提交
443 444 445 446 447
            Dim usesOperatorMethod As Boolean = False
            Dim operatorMethod As IMethodSymbol = Nothing
            Dim syntax As SyntaxNode = boundBinaryOperator.Syntax
            Dim type As ITypeSymbol = boundBinaryOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundBinaryOperator.ConstantValueOpt)
M
Manish Vasani 已提交
448 449 450
            Dim isLifted As Boolean = (boundBinaryOperator.OperatorKind And VisualBasic.BinaryOperatorKind.Lifted) <> 0
            Dim isChecked As Boolean = boundBinaryOperator.Checked
            Dim isCompareText As Boolean = (boundBinaryOperator.OperatorKind And VisualBasic.BinaryOperatorKind.CompareText) <> 0
J
jinuz420 已提交
451
            Dim isImplicit As Boolean = boundBinaryOperator.WasCompilerGenerated
452
            Return New LazyBinaryOperatorExpression(operatorKind, leftOperand, rightOperand, isLifted, isChecked, isCompareText, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
453
        End Function
H
Heejae Chang 已提交
454

455
        Private Function CreateBoundUserDefinedBinaryOperatorOperation(boundUserDefinedBinaryOperator As BoundUserDefinedBinaryOperator) As IBinaryOperatorExpression
M
Manish Vasani 已提交
456
            Dim operatorKind As BinaryOperatorKind = Helper.DeriveBinaryOperatorKind(boundUserDefinedBinaryOperator.OperatorKind, leftOpt:=Nothing)
H
Heejae Chang 已提交
457 458
            Dim leftOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetUserDefinedBinaryOperatorChild(boundUserDefinedBinaryOperator, 0))
            Dim rightOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetUserDefinedBinaryOperatorChild(boundUserDefinedBinaryOperator, 1))
H
Heejae Chang 已提交
459 460 461 462 463
            Dim operatorMethod As IMethodSymbol = If(boundUserDefinedBinaryOperator.UnderlyingExpression.Kind = BoundKind.Call, boundUserDefinedBinaryOperator.Call.Method, Nothing)
            Dim usesOperatorMethod As Boolean = operatorMethod IsNot Nothing
            Dim syntax As SyntaxNode = boundUserDefinedBinaryOperator.Syntax
            Dim type As ITypeSymbol = boundUserDefinedBinaryOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundUserDefinedBinaryOperator.ConstantValueOpt)
M
Manish Vasani 已提交
464 465 466
            Dim isLifted As Boolean = (boundUserDefinedBinaryOperator.OperatorKind And VisualBasic.BinaryOperatorKind.Lifted) <> 0
            Dim isChecked As Boolean = boundUserDefinedBinaryOperator.Checked
            Dim isCompareText As Boolean = False
J
jinuz420 已提交
467
            Dim isImplicit As Boolean = boundUserDefinedBinaryOperator.WasCompilerGenerated
468
            Return New LazyBinaryOperatorExpression(operatorKind, leftOperand, rightOperand, isLifted, isChecked, isCompareText, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
469
        End Function
H
Heejae Chang 已提交
470

471 472 473
        Private Function CreateBoundBinaryConditionalExpressionOperation(boundBinaryConditionalExpression As BoundBinaryConditionalExpression) As ICoalesceExpression
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryConditionalExpression.TestExpression))
            Dim whenNull As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryConditionalExpression.ElseExpression))
H
Heejae Chang 已提交
474 475 476
            Dim syntax As SyntaxNode = boundBinaryConditionalExpression.Syntax
            Dim type As ITypeSymbol = boundBinaryConditionalExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundBinaryConditionalExpression.ConstantValueOpt)
J
jinuz420 已提交
477
            Dim isImplicit As Boolean = boundBinaryConditionalExpression.WasCompilerGenerated
478
            Return New LazyCoalesceExpression(expression, whenNull, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
479
        End Function
H
Heejae Chang 已提交
480

481
        Private Function CreateBoundUserDefinedShortCircuitingOperatorOperation(boundUserDefinedShortCircuitingOperator As BoundUserDefinedShortCircuitingOperator) As IBinaryOperatorExpression
482
            Dim operatorKind As BinaryOperatorKind = If((boundUserDefinedShortCircuitingOperator.BitwiseOperator.OperatorKind And VisualBasic.BinaryOperatorKind.And) <> 0, BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr)
H
Heejae Chang 已提交
483 484
            Dim leftOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUserDefinedShortCircuitingOperator.LeftOperand))
            Dim rightOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUserDefinedShortCircuitingOperator.BitwiseOperator.Right))
H
Heejae Chang 已提交
485 486 487 488 489
            Dim usesOperatorMethod As Boolean = True
            Dim operatorMethod As IMethodSymbol = boundUserDefinedShortCircuitingOperator.BitwiseOperator.Call.Method
            Dim syntax As SyntaxNode = boundUserDefinedShortCircuitingOperator.Syntax
            Dim type As ITypeSymbol = boundUserDefinedShortCircuitingOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundUserDefinedShortCircuitingOperator.ConstantValueOpt)
M
Manish Vasani 已提交
490 491 492
            Dim isLifted As Boolean = (boundUserDefinedShortCircuitingOperator.BitwiseOperator.OperatorKind And VisualBasic.BinaryOperatorKind.Lifted) <> 0
            Dim isChecked As Boolean = False
            Dim isCompareText As Boolean = False
J
jinuz420 已提交
493
            Dim isImplicit As Boolean = boundUserDefinedShortCircuitingOperator.WasCompilerGenerated
494
            Return New LazyBinaryOperatorExpression(operatorKind, leftOperand, rightOperand, isLifted, isChecked, isCompareText, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
495
        End Function
H
Heejae Chang 已提交
496

497
        Private Function CreateBoundBadExpressionOperation(boundBadExpression As BoundBadExpression) As IInvalidExpression
H
Heejae Chang 已提交
498
            Dim children As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundBadExpression.ChildBoundNodes.SelectAsArray(Function(n) Create(n)))
H
Heejae Chang 已提交
499
            Dim syntax As SyntaxNode = boundBadExpression.Syntax
500 501
            ' We match semantic model here: If the Then expression IsMissing, we have a null type, rather than the ErrorType Of the bound node.
            Dim type As ITypeSymbol = If(syntax.IsMissing, Nothing, boundBadExpression.Type)
H
Heejae Chang 已提交
502
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundBadExpression.ConstantValueOpt)
J
jinuz420 已提交
503 504
            Dim isImplicit As Boolean = boundBadExpression.WasCompilerGenerated
            Return New LazyInvalidExpression(children, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
505
        End Function
H
Heejae Chang 已提交
506

507
        Private Function CreateBoundTryCastOperation(boundTryCast As BoundTryCast) As IConversionExpression
H
Heejae Chang 已提交
508
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTryCast.Operand))
H
Heejae Chang 已提交
509
            Dim syntax As SyntaxNode = boundTryCast.Syntax
510
            Dim conversion As Conversion = New Conversion(New KeyValuePair(Of ConversionKind, MethodSymbol)(boundTryCast.ConversionKind, Nothing))
511
            Dim isExplicitCastInCode As Boolean = True
512
            Dim isTryCast As Boolean = True
M
Manish Vasani 已提交
513
            Dim isChecked As Boolean = False
H
Heejae Chang 已提交
514 515
            Dim type As ITypeSymbol = boundTryCast.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundTryCast.ConstantValueOpt)
J
jinuz420 已提交
516 517
            Dim isImplicit As Boolean = boundTryCast.WasCompilerGenerated
            Return New LazyVisualBasicConversionExpression(operand, conversion, isExplicitCastInCode, isTryCast, isChecked, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
518
        End Function
H
Heejae Chang 已提交
519

520
        Private Function CreateBoundDirectCastOperation(boundDirectCast As BoundDirectCast) As IConversionExpression
H
Heejae Chang 已提交
521
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDirectCast.Operand))
H
Heejae Chang 已提交
522
            Dim syntax As SyntaxNode = boundDirectCast.Syntax
523
            Dim conversion As Conversion = New Conversion(New KeyValuePair(Of ConversionKind, MethodSymbol)(boundDirectCast.ConversionKind, Nothing))
524
            Dim isExplicit As Boolean = True
525
            Dim isTryCast As Boolean = False
M
Manish Vasani 已提交
526
            Dim isChecked As Boolean = False
H
Heejae Chang 已提交
527 528
            Dim type As ITypeSymbol = boundDirectCast.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundDirectCast.ConstantValueOpt)
J
jinuz420 已提交
529 530
            Dim isImplicit As Boolean = boundDirectCast.WasCompilerGenerated
            Return New LazyVisualBasicConversionExpression(operand, conversion, isExplicit, isTryCast, isChecked, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
531
        End Function
H
Heejae Chang 已提交
532

533
        Private Function CreateBoundConversionOperation(boundConversion As BoundConversion) As IOperation
H
Heejae Chang 已提交
534
            Dim syntax As SyntaxNode = boundConversion.Syntax
535 536 537 538 539 540 541 542 543 544 545 546 547 548

            If syntax.IsMissing Then
                ' If the underlying syntax IsMissing, then that means we're in case where the compiler generated a piece of syntax to fill in for
                ' an error, such as this case:
                '
                '  Dim i =
                '
                ' Semantic model has a special case here that we match: if the underlying syntax is missing, don't create a conversion expression,
                ' and instead directly return the operand, which will be a BoundBadExpression. When we generate a node for the BoundBadExpression,
                ' the resulting IOperation will also have a null Type.
                Debug.Assert(boundConversion.Operand.Kind = BoundKind.BadExpression)
                Return Create(boundConversion.Operand)
            End If

549 550 551 552 553 554 555 556 557 558 559 560
            Dim operand As Lazy(Of IOperation)
            Dim methodSymbol As MethodSymbol

            If (boundConversion.ConversionKind And VisualBasic.ConversionKind.UserDefined) = VisualBasic.ConversionKind.UserDefined Then
                Dim userDefinedConversion As BoundUserDefinedConversion = DirectCast(boundConversion.Operand, BoundUserDefinedConversion)
                methodSymbol = userDefinedConversion.Call.Method
                operand = New Lazy(Of IOperation)(Function() Create(userDefinedConversion.Operand))
            Else
                methodSymbol = Nothing
                operand = New Lazy(Of IOperation)(Function() Create(boundConversion.Operand))
            End If

561
            Dim conversion = New Conversion(New KeyValuePair(Of ConversionKind, MethodSymbol)(boundConversion.ConversionKind, methodSymbol))
562
            Dim isExplicit As Boolean = boundConversion.ExplicitCastInCode
563
            Dim isTryCast As Boolean = False
M
Manish Vasani 已提交
564
            Dim isChecked As Boolean = False
H
Heejae Chang 已提交
565 566
            Dim type As ITypeSymbol = boundConversion.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundConversion.ConstantValueOpt)
J
jinuz420 已提交
567 568
            Dim isImplicit As Boolean = boundConversion.WasCompilerGenerated
            Return New LazyVisualBasicConversionExpression(operand, conversion, isExplicit, isTryCast, isChecked, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
569
        End Function
H
Heejae Chang 已提交
570

571
        Private Function CreateBoundTernaryConditionalExpressionOperation(boundTernaryConditionalExpression As BoundTernaryConditionalExpression) As IConditionalExpression
H
Heejae Chang 已提交
572
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.Condition))
F
Fredric Silberberg 已提交
573 574
            Dim whenTrue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.WhenTrue))
            Dim whenFalse As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.WhenFalse))
H
Heejae Chang 已提交
575 576 577
            Dim syntax As SyntaxNode = boundTernaryConditionalExpression.Syntax
            Dim type As ITypeSymbol = boundTernaryConditionalExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundTernaryConditionalExpression.ConstantValueOpt)
J
jinuz420 已提交
578
            Dim isImplicit As Boolean = boundTernaryConditionalExpression.WasCompilerGenerated
F
Fredric Silberberg 已提交
579
            Return New LazyConditionalExpression(condition, whenTrue, whenFalse, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
580
        End Function
H
Heejae Chang 已提交
581

582
        Private Function CreateBoundTypeOfOperation(boundTypeOf As BoundTypeOf) As IIsTypeExpression
H
Heejae Chang 已提交
583
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTypeOf.Operand))
H
Heejae Chang 已提交
584
            Dim isType As ITypeSymbol = boundTypeOf.TargetType
585
            Dim isNotTypeExpression As Boolean = boundTypeOf.IsTypeOfIsNotExpression
H
Heejae Chang 已提交
586 587 588
            Dim syntax As SyntaxNode = boundTypeOf.Syntax
            Dim type As ITypeSymbol = boundTypeOf.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundTypeOf.ConstantValueOpt)
J
jinuz420 已提交
589
            Dim isImplicit As Boolean = boundTypeOf.WasCompilerGenerated
590
            Return New LazyIsTypeExpression(operand, isType, isNotTypeExpression, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
591
        End Function
H
Heejae Chang 已提交
592

593 594
        Private Function CreateBoundLateInvocationOperation(boundLateInvocation As BoundLateInvocation) As IOperation
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundLateInvocation.Member))
M
Manish Vasani 已提交
595 596 597 598 599 600
            Dim arguments As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
                    Return If(boundLateInvocation.ArgumentsOpt.IsDefault,
                    ImmutableArray(Of IOperation).Empty,
                    boundLateInvocation.ArgumentsOpt.SelectAsArray(Function(n) Create(n)))
                End Function)
601 602
            Dim argumentNames As ImmutableArray(Of String) = boundLateInvocation.ArgumentNamesOpt
            Dim argumentRefKinds As ImmutableArray(Of RefKind) = Nothing
603 604 605 606
            Dim syntax As SyntaxNode = boundLateInvocation.Syntax
            Dim type As ITypeSymbol = boundLateInvocation.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLateInvocation.ConstantValueOpt)
            Dim isImplicit As Boolean = boundLateInvocation.WasCompilerGenerated
M
Manish Vasani 已提交
607
            Return New LazyDynamicInvocationExpression(expression, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, constantValue, isImplicit)
608 609
        End Function

610
        Private Function CreateBoundObjectCreationExpressionOperation(boundObjectCreationExpression As BoundObjectCreationExpression) As IObjectCreationExpression
H
Heejae Chang 已提交
611
            Dim constructor As IMethodSymbol = boundObjectCreationExpression.ConstructorOpt
612
            Dim memberInitializers As Lazy(Of IObjectOrCollectionInitializerExpression) = New Lazy(Of IObjectOrCollectionInitializerExpression)(
H
Heejae Chang 已提交
613
                Function()
614
                    Return DirectCast(Create(boundObjectCreationExpression.InitializerOpt), IObjectOrCollectionInitializerExpression)
H
Heejae Chang 已提交
615 616 617 618 619 620 621 622 623 624 625 626 627
                End Function)

            Debug.Assert(boundObjectCreationExpression.ConstructorOpt IsNot Nothing OrElse boundObjectCreationExpression.Arguments.IsEmpty())
            Dim argumentsInEvaluationOrder As Lazy(Of ImmutableArray(Of IArgument)) = New Lazy(Of ImmutableArray(Of IArgument))(
                Function()
                    Return If(boundObjectCreationExpression.ConstructorOpt Is Nothing,
                        ImmutableArray(Of IArgument).Empty,
                        DeriveArguments(boundObjectCreationExpression.Arguments, boundObjectCreationExpression.ConstructorOpt.Parameters))
                End Function)

            Dim syntax As SyntaxNode = boundObjectCreationExpression.Syntax
            Dim type As ITypeSymbol = boundObjectCreationExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundObjectCreationExpression.ConstantValueOpt)
J
jinuz420 已提交
628 629
            Dim isImplicit As Boolean = boundObjectCreationExpression.WasCompilerGenerated
            Return New LazyObjectCreationExpression(constructor, memberInitializers, argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
630
        End Function
H
Heejae Chang 已提交
631

632 633 634 635 636
        Private Function CreateBoundObjectInitializerExpressionOperation(boundObjectInitializerExpression As BoundObjectInitializerExpression) As IObjectOrCollectionInitializerExpression
            Dim initializers As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundObjectInitializerExpression.Initializers.SelectAsArray(Function(n) Create(n)))
            Dim syntax As SyntaxNode = boundObjectInitializerExpression.Syntax
            Dim type As ITypeSymbol = boundObjectInitializerExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundObjectInitializerExpression.ConstantValueOpt)
J
jinuz420 已提交
637 638
            Dim isImplicit As Boolean = boundObjectInitializerExpression.WasCompilerGenerated
            Return New LazyObjectOrCollectionInitializerExpression(initializers, _semanticModel, syntax, type, constantValue, isImplicit)
639 640 641 642 643 644 645
        End Function

        Private Function CreateBoundCollectionInitializerExpressionOperation(boundCollectionInitializerExpression As BoundCollectionInitializerExpression) As IObjectOrCollectionInitializerExpression
            Dim initializers As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundCollectionInitializerExpression.Initializers.SelectAsArray(Function(n) CreateBoundCollectionElementInitializerOperation(n)))
            Dim syntax As SyntaxNode = boundCollectionInitializerExpression.Syntax
            Dim type As ITypeSymbol = boundCollectionInitializerExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundCollectionInitializerExpression.ConstantValueOpt)
J
jinuz420 已提交
646 647
            Dim isImplicit As Boolean = boundCollectionInitializerExpression.WasCompilerGenerated
            Return New LazyObjectOrCollectionInitializerExpression(initializers, _semanticModel, syntax, type, constantValue, isImplicit)
648 649 650
        End Function

        Private Function CreateBoundCollectionElementInitializerOperation(boundExpression As BoundExpression) As IOperation
M
Manish Vasani 已提交
651
            If boundExpression.Kind <> BoundKind.Call Then
652 653 654 655 656 657 658 659 660 661
                ' Error case, not an Add method call for collection element initializer
                Return Create(boundExpression)
            End If
            Dim boundCall = DirectCast(boundExpression, BoundCall)
            Dim addMethod As IMethodSymbol = boundCall.Method
            Dim arguments As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundCall.Arguments.SelectAsArray(Function(n) Create(n)))
            Dim isDynamic As Boolean = addMethod Is Nothing
            Dim syntax As SyntaxNode = boundExpression.Syntax
            Dim type As ITypeSymbol = boundExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundExpression.ConstantValueOpt)
J
jinuz420 已提交
662 663
            Dim isImplicit As Boolean = boundExpression.WasCompilerGenerated
            Return New LazyCollectionElementInitializerExpression(addMethod, arguments, isDynamic, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
664
        End Function
H
Heejae Chang 已提交
665

666
        Private Function CreateBoundNewTOperation(boundNewT As BoundNewT) As ITypeParameterObjectCreationExpression
667
            Dim initializer As Lazy(Of IObjectOrCollectionInitializerExpression) = New Lazy(Of IObjectOrCollectionInitializerExpression)(Function() DirectCast(Create(boundNewT.InitializerOpt), IObjectOrCollectionInitializerExpression))
H
Heejae Chang 已提交
668 669 670
            Dim syntax As SyntaxNode = boundNewT.Syntax
            Dim type As ITypeSymbol = boundNewT.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundNewT.ConstantValueOpt)
J
jinuz420 已提交
671 672
            Dim isImplicit As Boolean = boundNewT.WasCompilerGenerated
            Return New LazyTypeParameterObjectCreationExpression(initializer, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
673
        End Function
H
Heejae Chang 已提交
674

675
        Private Function CreateBoundArrayCreationOperation(boundArrayCreation As BoundArrayCreation) As IArrayCreationExpression
676
            Dim elementType As ITypeSymbol = TryCast(boundArrayCreation.Type, IArrayTypeSymbol)?.ElementType
H
Heejae Chang 已提交
677
            Dim dimensionSizes As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundArrayCreation.Bounds.SelectAsArray(Function(n) Create(n)))
H
Heejae Chang 已提交
678 679 680 681
            Dim initializer As Lazy(Of IArrayInitializer) = New Lazy(Of IArrayInitializer)(Function() DirectCast(Create(boundArrayCreation.InitializerOpt), IArrayInitializer))
            Dim syntax As SyntaxNode = boundArrayCreation.Syntax
            Dim type As ITypeSymbol = boundArrayCreation.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundArrayCreation.ConstantValueOpt)
J
jinuz420 已提交
682 683
            Dim isImplicit As Boolean = boundArrayCreation.WasCompilerGenerated
            Return New LazyArrayCreationExpression(elementType, dimensionSizes, initializer, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
684
        End Function
H
Heejae Chang 已提交
685

686
        Private Function CreateBoundArrayInitializationOperation(boundArrayInitialization As BoundArrayInitialization) As IArrayInitializer
H
Heejae Chang 已提交
687
            Dim elementValues As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundArrayInitialization.Initializers.SelectAsArray(Function(n) Create(n)))
H
Heejae Chang 已提交
688 689 690
            Dim syntax As SyntaxNode = boundArrayInitialization.Syntax
            Dim type As ITypeSymbol = boundArrayInitialization.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundArrayInitialization.ConstantValueOpt)
J
jinuz420 已提交
691 692
            Dim isImplicit As Boolean = boundArrayInitialization.WasCompilerGenerated
            Return New LazyArrayInitializer(elementValues, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
693
        End Function
H
Heejae Chang 已提交
694

695
        Private Function CreateBoundPropertyAccessOperation(boundPropertyAccess As BoundPropertyAccess) As IPropertyReferenceExpression
H
Heejae Chang 已提交
696 697 698 699 700 701 702 703 704 705
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
                    If boundPropertyAccess.PropertySymbol.IsShared Then
                        Return Nothing
                    Else
                        Return Create(boundPropertyAccess.ReceiverOpt)
                    End If
                End Function)

            Dim [property] As IPropertySymbol = boundPropertyAccess.PropertySymbol
706 707 708 709 710 711
            Dim argumentsInEvaluationOrder As Lazy(Of ImmutableArray(Of IArgument)) = New Lazy(Of ImmutableArray(Of IArgument))(
                Function()
                    Return If(boundPropertyAccess.Arguments.Length = 0,
                        ImmutableArray(Of IArgument).Empty,
                        DeriveArguments(boundPropertyAccess.Arguments, boundPropertyAccess.PropertySymbol.Parameters))
                End Function)
H
Heejae Chang 已提交
712 713 714
            Dim syntax As SyntaxNode = boundPropertyAccess.Syntax
            Dim type As ITypeSymbol = boundPropertyAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundPropertyAccess.ConstantValueOpt)
J
jinuz420 已提交
715 716
            Dim isImplicit As Boolean = boundPropertyAccess.WasCompilerGenerated
            Return New LazyPropertyReferenceExpression([property], instance, [property], argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
717
        End Function
H
Heejae Chang 已提交
718

719
        Private Function CreateBoundEventAccessOperation(boundEventAccess As BoundEventAccess) As IEventReferenceExpression
H
Heejae Chang 已提交
720 721
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
722 723 724 725 726
                    If boundEventAccess.EventSymbol.IsShared Then
                        Return Nothing
                    Else
                        Return Create(boundEventAccess.ReceiverOpt)
                    End If
H
Heejae Chang 已提交
727 728 729 730 731 732
                End Function)

            Dim [event] As IEventSymbol = boundEventAccess.EventSymbol
            Dim syntax As SyntaxNode = boundEventAccess.Syntax
            Dim type As ITypeSymbol = boundEventAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundEventAccess.ConstantValueOpt)
J
jinuz420 已提交
733 734
            Dim isImplicit As Boolean = boundEventAccess.WasCompilerGenerated
            Return New LazyEventReferenceExpression([event], instance, [event], _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
735
        End Function
H
Heejae Chang 已提交
736

737
        Private Function CreateBoundFieldAccessOperation(boundFieldAccess As BoundFieldAccess) As IFieldReferenceExpression
H
Heejae Chang 已提交
738
            Dim field As IFieldSymbol = boundFieldAccess.FieldSymbol
739
            Dim isDeclaration As Boolean = False
H
Heejae Chang 已提交
740 741 742 743 744
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
                    If boundFieldAccess.FieldSymbol.IsShared Then
                        Return Nothing
                    Else
H
Heejae Chang 已提交
745
                        Return Create(boundFieldAccess.ReceiverOpt)
H
Heejae Chang 已提交
746 747 748 749 750 751 752
                    End If
                End Function)

            Dim member As ISymbol = boundFieldAccess.FieldSymbol
            Dim syntax As SyntaxNode = boundFieldAccess.Syntax
            Dim type As ITypeSymbol = boundFieldAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundFieldAccess.ConstantValueOpt)
J
jinuz420 已提交
753
            Dim isImplicit As Boolean = boundFieldAccess.WasCompilerGenerated
754
            Return New LazyFieldReferenceExpression(field, isDeclaration, instance, member, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
755
        End Function
H
Heejae Chang 已提交
756

757
        Private Function CreateBoundConditionalAccessOperation(boundConditionalAccess As BoundConditionalAccess) As IConditionalAccessExpression
758 759
            Dim whenNotNull As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConditionalAccess.AccessExpression))
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConditionalAccess.Receiver))
H
Heejae Chang 已提交
760 761 762
            Dim syntax As SyntaxNode = boundConditionalAccess.Syntax
            Dim type As ITypeSymbol = boundConditionalAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundConditionalAccess.ConstantValueOpt)
J
jinuz420 已提交
763
            Dim isImplicit As Boolean = boundConditionalAccess.WasCompilerGenerated
764
            Return New LazyConditionalAccessExpression(whenNotNull, expression, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
765
        End Function
H
Heejae Chang 已提交
766

767
        Private Function CreateBoundConditionalAccessReceiverPlaceholderOperation(boundConditionalAccessReceiverPlaceholder As BoundConditionalAccessReceiverPlaceholder) As IConditionalAccessInstanceExpression
H
Heejae Chang 已提交
768 769 770
            Dim syntax As SyntaxNode = boundConditionalAccessReceiverPlaceholder.Syntax
            Dim type As ITypeSymbol = boundConditionalAccessReceiverPlaceholder.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundConditionalAccessReceiverPlaceholder.ConstantValueOpt)
J
jinuz420 已提交
771 772
            Dim isImplicit As Boolean = boundConditionalAccessReceiverPlaceholder.WasCompilerGenerated
            Return New ConditionalAccessInstanceExpression(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
773
        End Function
H
Heejae Chang 已提交
774

775
        Private Function CreateBoundParameterOperation(boundParameter As BoundParameter) As IParameterReferenceExpression
H
Heejae Chang 已提交
776 777 778 779
            Dim parameter As IParameterSymbol = boundParameter.ParameterSymbol
            Dim syntax As SyntaxNode = boundParameter.Syntax
            Dim type As ITypeSymbol = boundParameter.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundParameter.ConstantValueOpt)
J
jinuz420 已提交
780 781
            Dim isImplicit As Boolean = boundParameter.WasCompilerGenerated
            Return New ParameterReferenceExpression(parameter, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
782
        End Function
H
Heejae Chang 已提交
783

784
        Private Function CreateBoundLocalOperation(boundLocal As BoundLocal) As ILocalReferenceExpression
H
Heejae Chang 已提交
785
            Dim local As ILocalSymbol = boundLocal.LocalSymbol
786
            Dim isDeclaration As Boolean = False
H
Heejae Chang 已提交
787 788 789
            Dim syntax As SyntaxNode = boundLocal.Syntax
            Dim type As ITypeSymbol = boundLocal.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLocal.ConstantValueOpt)
J
jinuz420 已提交
790
            Dim isImplicit As Boolean = boundLocal.WasCompilerGenerated
791
            Return New LocalReferenceExpression(local, isDeclaration, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
792
        End Function
H
Heejae Chang 已提交
793

794
        Private Function CreateBoundLateMemberAccessOperation(boundLateMemberAccess As BoundLateMemberAccess) As IDynamicMemberReferenceExpression
H
Heejae Chang 已提交
795
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundLateMemberAccess.ReceiverOpt))
H
Heejae Chang 已提交
796
            Dim memberName As String = boundLateMemberAccess.NameOpt
797 798 799 800
            Dim typeArguments As ImmutableArray(Of ITypeSymbol) = ImmutableArray(Of ITypeSymbol).Empty
            If boundLateMemberAccess.TypeArgumentsOpt IsNot Nothing Then
                typeArguments = ImmutableArray(Of ITypeSymbol).CastUp(boundLateMemberAccess.TypeArgumentsOpt.Arguments)
            End If
801 802 803 804 805 806 807 808 809 810
            Dim containingType As ITypeSymbol = Nothing
            ' If there's nothing being late-bound against, something is very wrong
            Debug.Assert(boundLateMemberAccess.ReceiverOpt IsNot Nothing OrElse boundLateMemberAccess.ContainerTypeOpt IsNot Nothing)
            ' Only set containing type if the container is set to something, and either there is no reciever, or the receiver's type
            ' does not match the type of the containing type.
            If (boundLateMemberAccess.ContainerTypeOpt IsNot Nothing AndAlso
                (boundLateMemberAccess.ReceiverOpt Is Nothing OrElse
                 boundLateMemberAccess.ContainerTypeOpt <> boundLateMemberAccess.ReceiverOpt.Type)) Then
                containingType = boundLateMemberAccess.ContainerTypeOpt
            End If
H
Heejae Chang 已提交
811 812 813
            Dim syntax As SyntaxNode = boundLateMemberAccess.Syntax
            Dim type As ITypeSymbol = boundLateMemberAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLateMemberAccess.ConstantValueOpt)
J
jinuz420 已提交
814 815
            Dim isImplicit As Boolean = boundLateMemberAccess.WasCompilerGenerated
            Return New LazyDynamicMemberReferenceExpression(instance, memberName, typeArguments, containingType, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
816
        End Function
H
Heejae Chang 已提交
817

818
        Private Function CreateBoundFieldInitializerOperation(boundFieldInitializer As BoundFieldInitializer) As IFieldInitializer
H
Heejae Chang 已提交
819
            Dim initializedFields As ImmutableArray(Of IFieldSymbol) = ImmutableArray(Of IFieldSymbol).CastUp(boundFieldInitializer.InitializedFields)
H
Heejae Chang 已提交
820
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundFieldInitializer.InitialValue))
821
            Dim kind As OperationKind = OperationKind.FieldInitializer
H
Heejae Chang 已提交
822 823 824
            Dim syntax As SyntaxNode = boundFieldInitializer.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
825 826
            Dim isImplicit As Boolean = boundFieldInitializer.WasCompilerGenerated
            Return New LazyFieldInitializer(initializedFields, value, kind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
827
        End Function
H
Heejae Chang 已提交
828

829
        Private Function CreateBoundPropertyInitializerOperation(boundPropertyInitializer As BoundPropertyInitializer) As IPropertyInitializer
H
Heejae Chang 已提交
830
            Dim initializedProperty As IPropertySymbol = boundPropertyInitializer.InitializedProperties.FirstOrDefault()
H
Heejae Chang 已提交
831
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundPropertyInitializer.InitialValue))
832
            Dim kind As OperationKind = OperationKind.PropertyInitializer
H
Heejae Chang 已提交
833 834 835
            Dim syntax As SyntaxNode = boundPropertyInitializer.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
836 837
            Dim isImplicit As Boolean = boundPropertyInitializer.WasCompilerGenerated
            Return New LazyPropertyInitializer(initializedProperty, value, kind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
838
        End Function
H
Heejae Chang 已提交
839

840
        Private Function CreateBoundParameterEqualsValueOperation(boundParameterEqualsValue As BoundParameterEqualsValue) As IParameterInitializer
H
Heejae Chang 已提交
841
            Dim parameter As IParameterSymbol = boundParameterEqualsValue.Parameter
H
Heejae Chang 已提交
842
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundParameterEqualsValue.Value))
843
            Dim kind As OperationKind = OperationKind.ParameterInitializer
H
Heejae Chang 已提交
844 845 846
            Dim syntax As SyntaxNode = boundParameterEqualsValue.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
847 848
            Dim isImplicit As Boolean = boundParameterEqualsValue.WasCompilerGenerated
            Return New LazyParameterInitializer(parameter, value, kind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
849
        End Function
H
Heejae Chang 已提交
850

851
        Private Function CreateBoundRValuePlaceholderOperation(boundRValuePlaceholder As BoundRValuePlaceholder) As IPlaceholderExpression
H
Heejae Chang 已提交
852 853 854
            Dim syntax As SyntaxNode = boundRValuePlaceholder.Syntax
            Dim type As ITypeSymbol = boundRValuePlaceholder.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundRValuePlaceholder.ConstantValueOpt)
J
jinuz420 已提交
855 856
            Dim isImplicit As Boolean = boundRValuePlaceholder.WasCompilerGenerated
            Return New PlaceholderExpression(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
857
        End Function
H
Heejae Chang 已提交
858

859
        Private Function CreateBoundIfStatementOperation(boundIfStatement As BoundIfStatement) As IIfStatement
H
Heejae Chang 已提交
860 861 862
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundIfStatement.Condition))
            Dim ifTrueStatement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundIfStatement.Consequence))
            Dim ifFalseStatement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundIfStatement.AlternativeOpt))
H
Heejae Chang 已提交
863 864 865
            Dim syntax As SyntaxNode = boundIfStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
866 867
            Dim isImplicit As Boolean = boundIfStatement.WasCompilerGenerated
            Return New LazyIfStatement(condition, ifTrueStatement, ifFalseStatement, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
868
        End Function
H
Heejae Chang 已提交
869

870
        Private Function CreateBoundSelectStatementOperation(boundSelectStatement As BoundSelectStatement) As ISwitchStatement
H
Heejae Chang 已提交
871
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSelectStatement.ExpressionStatement.Expression))
872
            Dim cases As Lazy(Of ImmutableArray(Of ISwitchCase)) = New Lazy(Of ImmutableArray(Of ISwitchCase))(Function() GetSwitchStatementCases(boundSelectStatement.CaseBlocks))
H
Heejae Chang 已提交
873 874 875
            Dim syntax As SyntaxNode = boundSelectStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
876 877
            Dim isImplicit As Boolean = boundSelectStatement.WasCompilerGenerated
            Return New LazySwitchStatement(value, cases, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
878
        End Function
H
Heejae Chang 已提交
879

880
        Private Function CreateBoundSimpleCaseClauseOperation(boundSimpleCaseClause As BoundSimpleCaseClause) As ISingleValueCaseClause
881 882
            Dim clauseValue = GetSingleValueCaseClauseValue(boundSimpleCaseClause)
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(clauseValue))
883
            Dim CaseKind As CaseKind = CaseKind.SingleValue
H
Heejae Chang 已提交
884 885 886
            Dim syntax As SyntaxNode = boundSimpleCaseClause.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
887
            Dim isImplicit As Boolean = boundSimpleCaseClause.WasCompilerGenerated
888
            Return New LazySingleValueCaseClause(value, CaseKind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
889
        End Function
H
Heejae Chang 已提交
890

891
        Private Function CreateBoundRangeCaseClauseOperation(boundRangeCaseClause As BoundRangeCaseClause) As IRangeCaseClause
H
Heejae Chang 已提交
892 893 894 895 896 897 898 899
            Dim minimumValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
                    If boundRangeCaseClause.LowerBoundOpt IsNot Nothing Then
                        Return Create(boundRangeCaseClause.LowerBoundOpt)
                    End If

                    If boundRangeCaseClause.LowerBoundConditionOpt.Kind = BoundKind.BinaryOperator Then
                        Dim lowerBound As BoundBinaryOperator = DirectCast(boundRangeCaseClause.LowerBoundConditionOpt, BoundBinaryOperator)
900
                        If lowerBound.OperatorKind = VisualBasic.BinaryOperatorKind.GreaterThanOrEqual Then
H
Heejae Chang 已提交
901 902 903 904 905 906 907 908 909 910 911 912 913 914
                            Return Create(lowerBound.Right)
                        End If
                    End If

                    Return Nothing
                End Function)
            Dim maximumValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
                    If boundRangeCaseClause.UpperBoundOpt IsNot Nothing Then
                        Return Create(boundRangeCaseClause.UpperBoundOpt)
                    End If

                    If boundRangeCaseClause.UpperBoundConditionOpt.Kind = BoundKind.BinaryOperator Then
                        Dim upperBound As BoundBinaryOperator = DirectCast(boundRangeCaseClause.UpperBoundConditionOpt, BoundBinaryOperator)
915
                        If upperBound.OperatorKind = VisualBasic.BinaryOperatorKind.LessThanOrEqual Then
H
Heejae Chang 已提交
916 917 918 919 920 921
                            Return Create(upperBound.Right)
                        End If
                    End If

                    Return Nothing
                End Function)
922
            Dim CaseKind As CaseKind = CaseKind.Range
H
Heejae Chang 已提交
923 924 925
            Dim syntax As SyntaxNode = boundRangeCaseClause.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
926 927
            Dim isImplicit As Boolean = boundRangeCaseClause.WasCompilerGenerated
            Return New LazyRangeCaseClause(minimumValue, maximumValue, CaseKind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
928
        End Function
H
Heejae Chang 已提交
929

930
        Private Function CreateBoundRelationalCaseClauseOperation(boundRelationalCaseClause As BoundRelationalCaseClause) As IRelationalCaseClause
H
Heejae Chang 已提交
931 932
            Dim valueExpression = GetRelationalCaseClauseValue(boundRelationalCaseClause)
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(valueExpression))
M
Manish Vasani 已提交
933
            Dim relation As BinaryOperatorKind = If(valueExpression IsNot Nothing, Helper.DeriveBinaryOperatorKind(boundRelationalCaseClause.OperatorKind, leftOpt:=Nothing), BinaryOperatorKind.Invalid)
934
            Dim CaseKind As CaseKind = CaseKind.Relational
H
Heejae Chang 已提交
935 936 937
            Dim syntax As SyntaxNode = boundRelationalCaseClause.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
938 939
            Dim isImplicit As Boolean = boundRelationalCaseClause.WasCompilerGenerated
            Return New LazyRelationalCaseClause(value, relation, CaseKind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
940
        End Function
H
Heejae Chang 已提交
941

942
        Private Function CreateBoundDoLoopStatementOperation(boundDoLoopStatement As BoundDoLoopStatement) As IWhileUntilLoopStatement
H
Heejae Chang 已提交
943 944
            Dim isTopTest As Boolean = boundDoLoopStatement.ConditionIsTop
            Dim isWhile As Boolean = Not boundDoLoopStatement.ConditionIsUntil
H
Heejae Chang 已提交
945
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDoLoopStatement.ConditionOpt))
946
            Dim LoopKind As LoopKind = LoopKind.WhileUntil
H
Heejae Chang 已提交
947
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDoLoopStatement.Body))
H
Heejae Chang 已提交
948 949 950
            Dim syntax As SyntaxNode = boundDoLoopStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
951 952
            Dim isImplicit As Boolean = boundDoLoopStatement.WasCompilerGenerated
            Return New LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, LoopKind, body, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
953
        End Function
H
Heejae Chang 已提交
954

955
        Private Function CreateBoundForToStatementOperation(boundForToStatement As BoundForToStatement) As IForLoopStatement
956 957
            Dim before As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
958 959 960
                    Return GetForLoopStatementBefore(
                        boundForToStatement.ControlVariable,
                        boundForToStatement.InitialValue,
961 962
                        _semanticModel.CloneOperation(Create(boundForToStatement.LimitValue)),
                        _semanticModel.CloneOperation(Create(boundForToStatement.StepValue)))
963 964 965
                End Function)
            Dim atLoopBottom As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
966
                    Return GetForLoopStatementAtLoopBottom(
967
                        _semanticModel.CloneOperation(Create(boundForToStatement.ControlVariable)),
968 969
                        boundForToStatement.StepValue,
                        boundForToStatement.OperatorsOpt)
970
                End Function)
H
Heejae Chang 已提交
971
            Dim locals As ImmutableArray(Of ILocalSymbol) = ImmutableArray(Of ILocalSymbol).Empty
972 973
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
974 975 976 977 978
                    Return GetForWhileUntilLoopStatementCondition(
                        boundForToStatement.ControlVariable,
                        boundForToStatement.LimitValue,
                        boundForToStatement.StepValue,
                        boundForToStatement.OperatorsOpt)
979
                End Function)
980
            Dim LoopKind As LoopKind = LoopKind.For
H
Heejae Chang 已提交
981
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundForToStatement.Body))
H
Heejae Chang 已提交
982 983 984
            Dim syntax As SyntaxNode = boundForToStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
985 986
            Dim isImplicit As Boolean = boundForToStatement.WasCompilerGenerated
            Return New LazyForLoopStatement(before, atLoopBottom, locals, condition, LoopKind, body, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
987
        End Function
H
Heejae Chang 已提交
988

989
        Private Function CreateBoundForEachStatementOperation(boundForEachStatement As BoundForEachStatement) As IForEachLoopStatement
H
Heejae Chang 已提交
990
            Dim iterationVariable As ILocalSymbol = Nothing ' Manual
H
Heejae Chang 已提交
991
            Dim collection As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundForEachStatement.Collection))
992
            Dim LoopKind As LoopKind = LoopKind.ForEach
H
Heejae Chang 已提交
993
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundForEachStatement.Body))
H
Heejae Chang 已提交
994 995 996
            Dim syntax As SyntaxNode = boundForEachStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
997 998
            Dim isImplicit As Boolean = boundForEachStatement.WasCompilerGenerated
            Return New LazyForEachLoopStatement(iterationVariable, collection, LoopKind, body, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
999
        End Function
H
Heejae Chang 已提交
1000

1001
        Private Function CreateBoundTryStatementOperation(boundTryStatement As BoundTryStatement) As ITryStatement
H
Heejae Chang 已提交
1002
            Dim body As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundTryStatement.TryBlock), IBlockStatement))
H
Heejae Chang 已提交
1003
            Dim catches As Lazy(Of ImmutableArray(Of ICatchClause)) = New Lazy(Of ImmutableArray(Of ICatchClause))(Function() boundTryStatement.CatchBlocks.SelectAsArray(Function(n) DirectCast(Create(n), ICatchClause)))
H
Heejae Chang 已提交
1004 1005 1006 1007
            Dim finallyHandler As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundTryStatement.FinallyBlockOpt), IBlockStatement))
            Dim syntax As SyntaxNode = boundTryStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1008 1009
            Dim isImplicit As Boolean = boundTryStatement.WasCompilerGenerated
            Return New LazyTryStatement(body, catches, finallyHandler, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1010
        End Function
H
Heejae Chang 已提交
1011

1012
        Private Function CreateBoundCatchBlockOperation(boundCatchBlock As BoundCatchBlock) As ICatchClause
H
Heejae Chang 已提交
1013 1014
            Dim handler As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundCatchBlock.Body), IBlockStatement))
            Dim caughtType As ITypeSymbol = Nothing ' Manual
H
Heejae Chang 已提交
1015
            Dim filter As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundCatchBlock.ExceptionFilterOpt))
H
Heejae Chang 已提交
1016 1017 1018 1019
            Dim exceptionLocal As ILocalSymbol = boundCatchBlock.LocalOpt
            Dim syntax As SyntaxNode = boundCatchBlock.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1020 1021
            Dim isImplicit As Boolean = boundCatchBlock.WasCompilerGenerated
            Return New LazyCatchClause(handler, caughtType, filter, exceptionLocal, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1022
        End Function
H
Heejae Chang 已提交
1023

1024
        Private Function CreateBoundBlockOperation(boundBlock As BoundBlock) As IBlockStatement
1025 1026
            Dim statements As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
1027 1028
                    ' We should not be filtering OperationKind.None statements.
                    ' https://github.com/dotnet/roslyn/issues/21776
1029 1030
                    Return boundBlock.Statements.Select(Function(n) Create(n)).Where(Function(s) s.Kind <> OperationKind.None).ToImmutableArray()
                End Function)
H
Heejae Chang 已提交
1031 1032 1033 1034
            Dim locals As ImmutableArray(Of ILocalSymbol) = boundBlock.Locals.As(Of ILocalSymbol)()
            Dim syntax As SyntaxNode = boundBlock.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1035 1036
            Dim isImplicit As Boolean = boundBlock.WasCompilerGenerated
            Return New LazyBlockStatement(statements, locals, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1037
        End Function
H
Heejae Chang 已提交
1038

1039
        Private Function CreateBoundBadStatementOperation(boundBadStatement As BoundBadStatement) As IInvalidStatement
H
Heejae Chang 已提交
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
            Dim children As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
                    Dim builder As ArrayBuilder(Of IOperation) = ArrayBuilder(Of IOperation).GetInstance(boundBadStatement.ChildBoundNodes.Length)
                    For Each childNode In boundBadStatement.ChildBoundNodes
                        Dim operation = Create(childNode)
                        If operation IsNot Nothing Then
                            builder.Add(operation)
                        End If
                    Next

                    Return builder.ToImmutableAndFree()
                End Function)
H
Heejae Chang 已提交
1052 1053 1054
            Dim syntax As SyntaxNode = boundBadStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1055 1056
            Dim isImplicit As Boolean = boundBadStatement.WasCompilerGenerated
            Return New LazyInvalidStatement(children, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1057
        End Function
H
Heejae Chang 已提交
1058

1059
        Private Function CreateBoundReturnStatementOperation(boundReturnStatement As BoundReturnStatement) As IReturnStatement
H
Heejae Chang 已提交
1060
            Dim returnedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundReturnStatement.ExpressionOpt))
H
Heejae Chang 已提交
1061 1062 1063
            Dim syntax As SyntaxNode = boundReturnStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1064 1065
            Dim isImplicit As Boolean = boundReturnStatement.WasCompilerGenerated
            Return New LazyReturnStatement(OperationKind.ReturnStatement, returnedValue, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1066
        End Function
H
Heejae Chang 已提交
1067

1068
        Private Function CreateBoundThrowStatementOperation(boundThrowStatement As BoundThrowStatement) As IExpressionStatement
H
Heejae Chang 已提交
1069
            Dim thrownObject As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundThrowStatement.ExpressionOpt))
H
Heejae Chang 已提交
1070
            Dim syntax As SyntaxNode = boundThrowStatement.Syntax
1071 1072
            Dim expressionType As ITypeSymbol = boundThrowStatement.ExpressionOpt?.Type
            Dim statementType As ITypeSymbol = Nothing
H
Heejae Chang 已提交
1073
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1074
            Dim isImplicit As Boolean = boundThrowStatement.WasCompilerGenerated
1075 1076
            Dim throwExpression As IOperation = New LazyThrowExpression(thrownObject, _semanticModel, syntax, expressionType, constantValue, isImplicit)
            Return New ExpressionStatement(throwExpression, _semanticModel, syntax, statementType, constantValue, isImplicit)
H
Heejae Chang 已提交
1077
        End Function
H
Heejae Chang 已提交
1078

1079
        Private Function CreateBoundWhileStatementOperation(boundWhileStatement As BoundWhileStatement) As IWhileUntilLoopStatement
H
Heejae Chang 已提交
1080 1081
            Dim isTopTest As Boolean = True
            Dim isWhile As Boolean = True
H
Heejae Chang 已提交
1082
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWhileStatement.Condition))
1083
            Dim LoopKind As LoopKind = LoopKind.WhileUntil
H
Heejae Chang 已提交
1084
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWhileStatement.Body))
H
Heejae Chang 已提交
1085 1086 1087
            Dim syntax As SyntaxNode = boundWhileStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1088 1089
            Dim isImplicit As Boolean = boundWhileStatement.WasCompilerGenerated
            Return New LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, LoopKind, body, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1090
        End Function
H
Heejae Chang 已提交
1091

1092
        Private Function CreateBoundDimStatementOperation(boundDimStatement As BoundDimStatement) As IVariableDeclarationStatement
H
Heejae Chang 已提交
1093
            Dim declarations As Lazy(Of ImmutableArray(Of IVariableDeclaration)) = New Lazy(Of ImmutableArray(Of IVariableDeclaration))(Function() GetVariableDeclarationStatementVariables(boundDimStatement))
H
Heejae Chang 已提交
1094 1095 1096
            Dim syntax As SyntaxNode = boundDimStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1097 1098
            Dim isImplicit As Boolean = boundDimStatement.WasCompilerGenerated
            Return New LazyVariableDeclarationStatement(declarations, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1099
        End Function
H
Heejae Chang 已提交
1100

1101
        Private Function CreateBoundYieldStatementOperation(boundYieldStatement As BoundYieldStatement) As IReturnStatement
H
Heejae Chang 已提交
1102
            Dim returnedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundYieldStatement.Expression))
H
Heejae Chang 已提交
1103 1104 1105
            Dim syntax As SyntaxNode = boundYieldStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1106 1107
            Dim isImplicit As Boolean = boundYieldStatement.WasCompilerGenerated
            Return New LazyReturnStatement(OperationKind.YieldReturnStatement, returnedValue, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1108
        End Function
H
Heejae Chang 已提交
1109

1110
        Private Function CreateBoundLabelStatementOperation(boundLabelStatement As BoundLabelStatement) As ILabeledStatement
H
Heejae Chang 已提交
1111
            Dim label As ILabelSymbol = boundLabelStatement.Label
1112
            Dim statement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Nothing)
H
Heejae Chang 已提交
1113 1114 1115
            Dim syntax As SyntaxNode = boundLabelStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1116
            Dim isImplicit As Boolean = boundLabelStatement.WasCompilerGenerated
1117
            Return New LazyLabeledStatement(label, statement, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1118
        End Function
H
Heejae Chang 已提交
1119

1120
        Private Function CreateBoundGotoStatementOperation(boundGotoStatement As BoundGotoStatement) As IBranchStatement
H
Heejae Chang 已提交
1121
            Dim target As ILabelSymbol = boundGotoStatement.Label
1122
            Dim branchKind As BranchKind = BranchKind.GoTo
H
Heejae Chang 已提交
1123 1124 1125
            Dim syntax As SyntaxNode = boundGotoStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1126 1127
            Dim isImplicit As Boolean = boundGotoStatement.WasCompilerGenerated
            Return New BranchStatement(target, branchKind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1128
        End Function
H
Heejae Chang 已提交
1129

1130
        Private Function CreateBoundContinueStatementOperation(boundContinueStatement As BoundContinueStatement) As IBranchStatement
H
Heejae Chang 已提交
1131
            Dim target As ILabelSymbol = boundContinueStatement.Label
1132
            Dim branchKind As BranchKind = BranchKind.Continue
H
Heejae Chang 已提交
1133 1134 1135
            Dim syntax As SyntaxNode = boundContinueStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1136 1137
            Dim isImplicit As Boolean = boundContinueStatement.WasCompilerGenerated
            Return New BranchStatement(target, branchKind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1138
        End Function
H
Heejae Chang 已提交
1139

1140
        Private Function CreateBoundExitStatementOperation(boundExitStatement As BoundExitStatement) As IBranchStatement
H
Heejae Chang 已提交
1141
            Dim target As ILabelSymbol = boundExitStatement.Label
1142
            Dim branchKind As BranchKind = BranchKind.Break
H
Heejae Chang 已提交
1143 1144 1145
            Dim syntax As SyntaxNode = boundExitStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1146 1147
            Dim isImplicit As Boolean = boundExitStatement.WasCompilerGenerated
            Return New BranchStatement(target, branchKind, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1148
        End Function
H
Heejae Chang 已提交
1149

1150
        Private Function CreateBoundSyncLockStatementOperation(boundSyncLockStatement As BoundSyncLockStatement) As ILockStatement
1151
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSyncLockStatement.LockExpression))
H
Heejae Chang 已提交
1152
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSyncLockStatement.Body))
H
Heejae Chang 已提交
1153 1154 1155
            Dim syntax As SyntaxNode = boundSyncLockStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1156
            Dim isImplicit As Boolean = boundSyncLockStatement.WasCompilerGenerated
1157
            Return New LazyLockStatement(expression, body, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1158
        End Function
H
Heejae Chang 已提交
1159

1160
        Private Function CreateBoundNoOpStatementOperation(boundNoOpStatement As BoundNoOpStatement) As IEmptyStatement
H
Heejae Chang 已提交
1161 1162 1163
            Dim syntax As SyntaxNode = boundNoOpStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1164 1165
            Dim isImplicit As Boolean = boundNoOpStatement.WasCompilerGenerated
            Return New EmptyStatement(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1166
        End Function
H
Heejae Chang 已提交
1167

1168
        Private Function CreateBoundStopStatementOperation(boundStopStatement As BoundStopStatement) As IStopStatement
H
Heejae Chang 已提交
1169 1170 1171
            Dim syntax As SyntaxNode = boundStopStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1172 1173
            Dim isImplicit As Boolean = boundStopStatement.WasCompilerGenerated
            Return New StopStatement(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1174
        End Function
H
Heejae Chang 已提交
1175

1176
        Private Function CreateBoundEndStatementOperation(boundEndStatement As BoundEndStatement) As IEndStatement
H
Heejae Chang 已提交
1177 1178 1179
            Dim syntax As SyntaxNode = boundEndStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1180 1181
            Dim isImplicit As Boolean = boundEndStatement.WasCompilerGenerated
            Return New EndStatement(_semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1182
        End Function
H
Heejae Chang 已提交
1183

1184
        Private Function CreateBoundWithStatementOperation(boundWithStatement As BoundWithStatement) As IWithStatement
H
Heejae Chang 已提交
1185 1186
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWithStatement.Body))
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWithStatement.OriginalExpression))
H
Heejae Chang 已提交
1187 1188 1189
            Dim syntax As SyntaxNode = boundWithStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1190 1191
            Dim isImplicit As Boolean = boundWithStatement.WasCompilerGenerated
            Return New LazyWithStatement(body, value, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1192
        End Function
H
Heejae Chang 已提交
1193

1194
        Private Function CreateBoundUsingStatementOperation(boundUsingStatement As BoundUsingStatement) As IUsingStatement
H
Heejae Chang 已提交
1195
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUsingStatement.Body))
1196 1197 1198 1199
            Dim declaration As Lazy(Of IVariableDeclarationStatement) = New Lazy(Of IVariableDeclarationStatement)(
                Function()
                    Return GetUsingStatementDeclaration(boundUsingStatement.ResourceList, DirectCast(boundUsingStatement.Syntax, UsingBlockSyntax).UsingStatement)
                End Function)
H
Heejae Chang 已提交
1200
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUsingStatement.ResourceExpressionOpt))
H
Heejae Chang 已提交
1201 1202 1203
            Dim syntax As SyntaxNode = boundUsingStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1204 1205
            Dim isImplicit As Boolean = boundUsingStatement.WasCompilerGenerated
            Return New LazyUsingStatement(body, declaration, value, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1206
        End Function
H
Heejae Chang 已提交
1207

1208
        Private Function CreateBoundExpressionStatementOperation(boundExpressionStatement As BoundExpressionStatement) As IExpressionStatement
H
Heejae Chang 已提交
1209
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundExpressionStatement.Expression))
H
Heejae Chang 已提交
1210 1211 1212
            Dim syntax As SyntaxNode = boundExpressionStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1213 1214
            Dim isImplicit As Boolean = boundExpressionStatement.WasCompilerGenerated
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1215
        End Function
H
Heejae Chang 已提交
1216

1217
        Private Function CreateBoundRaiseEventStatementOperation(boundRaiseEventStatement As BoundRaiseEventStatement) As IExpressionStatement
H
Heejae Chang 已提交
1218
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundRaiseEventStatement.EventInvocation))
H
Heejae Chang 已提交
1219 1220 1221
            Dim syntax As SyntaxNode = boundRaiseEventStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1222 1223
            Dim isImplicit As Boolean = boundRaiseEventStatement.WasCompilerGenerated
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1224
        End Function
H
Heejae Chang 已提交
1225

1226
        Private Function CreateBoundAddHandlerStatementOperation(boundAddHandlerStatement As BoundAddHandlerStatement) As IExpressionStatement
1227
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetAddRemoveHandlerStatementExpression(boundAddHandlerStatement))
H
Heejae Chang 已提交
1228 1229 1230
            Dim syntax As SyntaxNode = boundAddHandlerStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1231 1232
            Dim isImplicit As Boolean = boundAddHandlerStatement.WasCompilerGenerated
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1233
        End Function
H
Heejae Chang 已提交
1234

1235
        Private Function CreateBoundRemoveHandlerStatementOperation(boundRemoveHandlerStatement As BoundRemoveHandlerStatement) As IExpressionStatement
1236
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetAddRemoveHandlerStatementExpression(boundRemoveHandlerStatement))
H
Heejae Chang 已提交
1237 1238 1239
            Dim syntax As SyntaxNode = boundRemoveHandlerStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
J
jinuz420 已提交
1240 1241
            Dim isImplicit As Boolean = boundRemoveHandlerStatement.WasCompilerGenerated
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue, isImplicit)
H
Heejae Chang 已提交
1242
        End Function
1243

1244 1245
        Private Function CreateBoundTupleExpressionOperation(boundTupleExpression As BoundTupleExpression) As ITupleExpression
            Dim elements As New Lazy(Of ImmutableArray(Of IOperation))(Function() boundTupleExpression.Arguments.SelectAsArray(Function(element) Create(element)))
1246 1247
            Dim syntax As SyntaxNode = boundTupleExpression.Syntax
            Dim type As ITypeSymbol = boundTupleExpression.Type
1248
            Dim constantValue As [Optional](Of Object) = Nothing
J
jinuz420 已提交
1249 1250
            Dim isImplicit As Boolean = boundTupleExpression.WasCompilerGenerated
            Return New LazyTupleExpression(elements, _semanticModel, syntax, type, constantValue, isImplicit)
1251
        End Function
1252

1253
        Private Function CreateBoundInterpolatedStringExpressionOperation(boundInterpolatedString As BoundInterpolatedStringExpression) As IInterpolatedStringExpression
1254 1255 1256 1257 1258
            Dim parts As New Lazy(Of ImmutableArray(Of IInterpolatedStringContent))(
                Function()
                    Return boundInterpolatedString.Contents.SelectAsArray(Function(interpolatedStringContent) CreateBoundInterpolatedStringContentOperation(interpolatedStringContent))
                End Function)

1259 1260 1261
            Dim syntax As SyntaxNode = boundInterpolatedString.Syntax
            Dim type As ITypeSymbol = boundInterpolatedString.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundInterpolatedString.ConstantValueOpt)
J
jinuz420 已提交
1262 1263
            Dim isImplicit As Boolean = boundInterpolatedString.WasCompilerGenerated
            Return New LazyInterpolatedStringExpression(parts, _semanticModel, syntax, type, constantValue, isImplicit)
1264 1265
        End Function

1266
        Private Function CreateBoundInterpolatedStringContentOperation(boundNode As BoundNode) As IInterpolatedStringContent
M
Manish Vasani 已提交
1267
            If boundNode.Kind = BoundKind.Interpolation Then
M
Manish Vasani 已提交
1268
                Return DirectCast(Create(boundNode), IInterpolatedStringContent)
M
Manish Vasani 已提交
1269 1270
            Else
                Return CreateBoundInterpolatedStringTextOperation(boundNode)
1271 1272 1273
            End If
        End Function

1274
        Private Function CreateBoundInterpolationOperation(boundInterpolation As BoundInterpolation) As IInterpolation
1275 1276 1277 1278 1279 1280
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundInterpolation.Expression))
            Dim alignment As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundInterpolation.AlignmentOpt))
            Dim format As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundInterpolation.FormatStringOpt))
            Dim syntax As SyntaxNode = boundInterpolation.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = Nothing
J
jinuz420 已提交
1281 1282
            Dim isImplicit As Boolean = boundInterpolation.WasCompilerGenerated
            Return New LazyInterpolation(expression, alignment, format, _semanticModel, syntax, type, constantValue, isImplicit)
1283 1284
        End Function

1285
        Private Function CreateBoundInterpolatedStringTextOperation(boundNode As BoundNode) As IInterpolatedStringText
M
Manish Vasani 已提交
1286 1287
            Dim text As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundNode))
            Dim syntax As SyntaxNode = boundNode.Syntax
1288 1289
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = Nothing
J
jinuz420 已提交
1290 1291
            Dim isImplicit As Boolean = boundNode.WasCompilerGenerated
            Return New LazyInterpolatedStringText(text, _semanticModel, syntax, type, constantValue, isImplicit)
1292
        End Function
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302

        Private Function CreateBoundAnonymousTypeCreationExpressionOperation(boundAnonymousTypeCreationExpression As BoundAnonymousTypeCreationExpression) As IAnonymousObjectCreationExpression
            Dim initializers As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
                    Return GetAnonymousTypeCreationInitializers(boundAnonymousTypeCreationExpression)
                End Function)

            Dim syntax As SyntaxNode = boundAnonymousTypeCreationExpression.Syntax
            Dim type As ITypeSymbol = boundAnonymousTypeCreationExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAnonymousTypeCreationExpression.ConstantValueOpt)
J
jinuz420 已提交
1303 1304
            Dim isImplicit As Boolean = boundAnonymousTypeCreationExpression.WasCompilerGenerated
            Return New LazyAnonymousObjectCreationExpression(initializers, _semanticModel, syntax, type, constantValue, isImplicit)
1305 1306 1307 1308 1309
        End Function

        Private Function CreateBoundAnonymousTypePropertyAccessOperation(boundAnonymousTypePropertyAccess As BoundAnonymousTypePropertyAccess) As IPropertyReferenceExpression
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Nothing)
            Dim [property] As IPropertySymbol = DirectCast(boundAnonymousTypePropertyAccess.ExpressionSymbol, IPropertySymbol)
M
Manish Vasani 已提交
1310
            Dim argumentsInEvaluationOrder As Lazy(Of ImmutableArray(Of IArgument)) = New Lazy(Of ImmutableArray(Of IArgument))(Function() ImmutableArray(Of IArgument).Empty)
1311 1312 1313
            Dim syntax As SyntaxNode = boundAnonymousTypePropertyAccess.Syntax
            Dim type As ITypeSymbol = boundAnonymousTypePropertyAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAnonymousTypePropertyAccess.ConstantValueOpt)
J
jinuz420 已提交
1314 1315
            Dim isImplicit As Boolean = boundAnonymousTypePropertyAccess.WasCompilerGenerated
            Return New LazyPropertyReferenceExpression([property], instance, [property], argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue, isImplicit)
1316
        End Function
H
Heejae Chang 已提交
1317 1318 1319 1320
    End Class
End Namespace