VisualBasicOperationFactory.vb 86.5 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.Syntax
H
Heejae Chang 已提交
8 9 10

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

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

15 16 17 18 19 20
        Private ReadOnly _semanticModel As SemanticModel

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

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

H
Heejae Chang 已提交
26 27
            ' this should be removed once this issue is fixed
            ' https://github.com/dotnet/roslyn/issues/21186
28 29 30
            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.
31 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
                Return CreateInternal(boundNode).Clone()
34 35
            End If

H
Heejae Chang 已提交
36 37
            ' this should be removed once this issue is fixed
            ' https://github.com/dotnet/roslyn/issues/21187
38 39 40 41 42 43 44
            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

45
            Return _cache.GetOrAdd(boundNode, Function(n) CreateInternal(n))
H
Heejae Chang 已提交
46 47
        End Function

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
        Private Function IsIgnoredNode(boundNode As BoundNode) As Boolean
            ' since boundNode doesn't have parent pointer, it can't just look around using bound node
            ' it needs to use syntax node
            If TypeOf boundNode Is BoundExpressionStatement Then
                Return If(boundNode?.Syntax.Kind() = SyntaxKind.SelectStatement, False)
            ElseIf TypeOf boundNode Is BoundCaseBlock Then
                Return True
            ElseIf TypeOf boundNode Is BoundCaseStatement Then
                Return True
            ElseIf TypeOf boundNode Is BoundEventAccess Then
                Return If(boundNode?.Syntax.Parent.Kind() = SyntaxKind.AddHandlerStatement, False) OrElse
                       If(boundNode?.Syntax.Parent.Kind() = SyntaxKind.RemoveHandlerStatement, False)
            End If

            Return False
        End Function

65
        Private Function CreateInternal(boundNode As BoundNode) As IOperation
H
Heejae Chang 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78
            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))
79 80
                Case BoundKind.NameOfOperator
                    Return CreateBoundNameOfOperatorOperation(DirectCast(boundNode, BoundNameOfOperator))
H
Heejae Chang 已提交
81 82 83 84 85 86 87 88 89 90 91 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
                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.UserDefinedConversion
                    Return CreateBoundUserDefinedConversionOperation(DirectCast(boundNode, BoundUserDefinedConversion))
                Case BoundKind.TernaryConditionalExpression
                    Return CreateBoundTernaryConditionalExpressionOperation(DirectCast(boundNode, BoundTernaryConditionalExpression))
                Case BoundKind.TypeOf
                    Return CreateBoundTypeOfOperation(DirectCast(boundNode, BoundTypeOf))
                Case BoundKind.ObjectCreationExpression
                    Return CreateBoundObjectCreationExpressionOperation(DirectCast(boundNode, BoundObjectCreationExpression))
119 120 121 122
                Case BoundKind.ObjectInitializerExpression
                    Return CreateBoundObjectInitializerExpressionOperation(DirectCast(boundNode, BoundObjectInitializerExpression))
                Case BoundKind.CollectionInitializerExpression
                    Return CreateBoundCollectionInitializerExpressionOperation(DirectCast(boundNode, BoundCollectionInitializerExpression))
H
Heejae Chang 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 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
                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))
                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))
215 216
                Case BoundKind.TupleLiteral,
                     BoundKind.ConvertedTupleLiteral
217
                    Return CreateBoundTupleExpressionOperation(DirectCast(boundNode, BoundTupleExpression))
218 219 220
                Case BoundKind.InterpolatedStringExpression
                    Return CreateBoundInterpolatedStringExpressionOperation(DirectCast(boundNode, BoundInterpolatedStringExpression))
                Case BoundKind.Interpolation
M
Manish Vasani 已提交
221
                    Return CreateBoundInterpolationOperation(DirectCast(boundNode, BoundInterpolation))
222 223 224 225 226 227
                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 已提交
228
                Case Else
229
                    Dim constantValue = ConvertToOptional(TryCast(boundNode, BoundExpression)?.ConstantValueOpt)
230
                    Return Operation.CreateOperationNone(_semanticModel, boundNode.Syntax, constantValue, Function() GetIOperationChildren(boundNode))
H
Heejae Chang 已提交
231 232
            End Select
        End Function
H
Heejae Chang 已提交
233

234
        Private Function GetIOperationChildren(boundNode As BoundNode) As ImmutableArray(Of IOperation)
235 236 237 238 239 240 241 242 243 244 245 246 247 248
            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

249
        Private Function CreateBoundAssignmentOperatorOperation(boundAssignmentOperator As BoundAssignmentOperator) As IOperation
H
Heejae Chang 已提交
250 251
            Dim kind = GetAssignmentKind(boundAssignmentOperator)
            If kind = OperationKind.CompoundAssignmentExpression Then
252 253 254 255
                ' convert Right to IOperation temporarily. we do this to get right operand, operator method and etc
                Dim temporaryRight = DirectCast(Create(boundAssignmentOperator.Right), IBinaryOperatorExpression)

                Dim binaryOperationKind As BinaryOperationKind = temporaryRight.BinaryOperationKind
H
Heejae Chang 已提交
256
                Dim target As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundAssignmentOperator.Left))
257 258 259 260 261 262 263 264

                ' 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 已提交
265 266 267
                Dim syntax As SyntaxNode = boundAssignmentOperator.Syntax
                Dim type As ITypeSymbol = boundAssignmentOperator.Type
                Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAssignmentOperator.ConstantValueOpt)
268
                Return New LazyCompoundAssignmentExpression(binaryOperationKind, target, value, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
269
            Else
H
Heejae Chang 已提交
270 271
                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 已提交
272 273 274
                Dim syntax As SyntaxNode = boundAssignmentOperator.Syntax
                Dim type As ITypeSymbol = boundAssignmentOperator.Type
                Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAssignmentOperator.ConstantValueOpt)
275
                Return New LazySimpleAssignmentExpression(target, value, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
276 277
            End If
        End Function
H
Heejae Chang 已提交
278

279
        Private Function CreateBoundMeReferenceOperation(boundMeReference As BoundMeReference) As IInstanceReferenceExpression
H
Heejae Chang 已提交
280 281 282 283
            Dim instanceReferenceKind As InstanceReferenceKind = If(boundMeReference.WasCompilerGenerated, InstanceReferenceKind.Implicit, InstanceReferenceKind.Explicit)
            Dim syntax As SyntaxNode = boundMeReference.Syntax
            Dim type As ITypeSymbol = boundMeReference.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundMeReference.ConstantValueOpt)
284
            Return New InstanceReferenceExpression(instanceReferenceKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
285
        End Function
H
Heejae Chang 已提交
286

287
        Private Function CreateBoundMyBaseReferenceOperation(boundMyBaseReference As BoundMyBaseReference) As IInstanceReferenceExpression
H
Heejae Chang 已提交
288 289 290 291
            Dim instanceReferenceKind As InstanceReferenceKind = InstanceReferenceKind.BaseClass
            Dim syntax As SyntaxNode = boundMyBaseReference.Syntax
            Dim type As ITypeSymbol = boundMyBaseReference.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundMyBaseReference.ConstantValueOpt)
292
            Return New InstanceReferenceExpression(instanceReferenceKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
293
        End Function
H
Heejae Chang 已提交
294

295
        Private Function CreateBoundMyClassReferenceOperation(boundMyClassReference As BoundMyClassReference) As IInstanceReferenceExpression
H
Heejae Chang 已提交
296 297 298 299
            Dim instanceReferenceKind As InstanceReferenceKind = InstanceReferenceKind.ThisClass
            Dim syntax As SyntaxNode = boundMyClassReference.Syntax
            Dim type As ITypeSymbol = boundMyClassReference.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundMyClassReference.ConstantValueOpt)
300
            Return New InstanceReferenceExpression(instanceReferenceKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
301
        End Function
H
Heejae Chang 已提交
302

303
        Private Function CreateBoundLiteralOperation(boundLiteral As BoundLiteral) As ILiteralExpression
H
Heejae Chang 已提交
304 305 306 307
            Dim text As String = boundLiteral.Syntax.ToString()
            Dim syntax As SyntaxNode = boundLiteral.Syntax
            Dim type As ITypeSymbol = boundLiteral.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLiteral.ConstantValueOpt)
308
            Return New LiteralExpression(text, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
309
        End Function
H
Heejae Chang 已提交
310

311
        Private Function CreateBoundAwaitOperatorOperation(boundAwaitOperator As BoundAwaitOperator) As IAwaitExpression
H
Heejae Chang 已提交
312
            Dim awaitedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundAwaitOperator.Operand))
H
Heejae Chang 已提交
313 314 315
            Dim syntax As SyntaxNode = boundAwaitOperator.Syntax
            Dim type As ITypeSymbol = boundAwaitOperator.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAwaitOperator.ConstantValueOpt)
316
            Return New LazyAwaitExpression(awaitedValue, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
317
        End Function
H
Heejae Chang 已提交
318

319 320 321 322 323
        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)
324
            Return New LazyNameOfExpression(argument, _semanticModel, syntax, type, constantValue)
325 326
        End Function

327
        Private Function CreateBoundLambdaOperation(boundLambda As BoundLambda) As ILambdaExpression
H
Heejae Chang 已提交
328 329 330 331 332
            Dim signature As IMethodSymbol = boundLambda.LambdaSymbol
            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)
333
            Return New LazyLambdaExpression(signature, body, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
334
        End Function
H
Heejae Chang 已提交
335

336
        Private Function CreateBoundCallOperation(boundCall As BoundCall) As IInvocationExpression
H
Heejae Chang 已提交
337
            Dim targetMethod As IMethodSymbol = boundCall.Method
H
Heejae Chang 已提交
338
            Dim receiver As IOperation = Create(boundCall.ReceiverOpt)
H
Heejae Chang 已提交
339

340 341 342 343 344 345 346 347 348 349 350 351 352
            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 已提交
353 354 355
            Dim syntax As SyntaxNode = boundCall.Syntax
            Dim type As ITypeSymbol = boundCall.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundCall.ConstantValueOpt)
356
            Return New LazyInvocationExpression(targetMethod, instance, isVirtual, argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
357
        End Function
H
Heejae Chang 已提交
358

359
        Private Function CreateBoundOmittedArgumentOperation(boundOmittedArgument As BoundOmittedArgument) As IOmittedArgumentExpression
H
Heejae Chang 已提交
360 361 362
            Dim syntax As SyntaxNode = boundOmittedArgument.Syntax
            Dim type As ITypeSymbol = boundOmittedArgument.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundOmittedArgument.ConstantValueOpt)
363
            Return New OmittedArgumentExpression(_semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
364
        End Function
H
Heejae Chang 已提交
365

366
        Private Function CreateBoundParenthesizedOperation(boundParenthesized As BoundParenthesized) As IParenthesizedExpression
H
Heejae Chang 已提交
367
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundParenthesized.Expression))
H
Heejae Chang 已提交
368 369 370
            Dim syntax As SyntaxNode = boundParenthesized.Syntax
            Dim type As ITypeSymbol = boundParenthesized.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundParenthesized.ConstantValueOpt)
371
            Return New LazyParenthesizedExpression(operand, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
372
        End Function
H
Heejae Chang 已提交
373

374
        Private Function CreateBoundArrayAccessOperation(boundArrayAccess As BoundArrayAccess) As IArrayElementReferenceExpression
H
Heejae Chang 已提交
375
            Dim arrayReference As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundArrayAccess.Expression))
H
Heejae Chang 已提交
376 377 378 379
            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)
380
            Return New LazyArrayElementReferenceExpression(arrayReference, indices, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
381
        End Function
H
Heejae Chang 已提交
382

383
        Private Function CreateBoundUnaryOperatorOperation(boundUnaryOperator As BoundUnaryOperator) As IUnaryOperatorExpression
H
Heejae Chang 已提交
384
            Dim unaryOperationKind As UnaryOperationKind = Helper.DeriveUnaryOperationKind(boundUnaryOperator.OperatorKind, boundUnaryOperator.Operand)
H
Heejae Chang 已提交
385
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUnaryOperator.Operand))
H
Heejae Chang 已提交
386 387 388 389 390
            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)
391
            Return New LazyUnaryOperatorExpression(unaryOperationKind, operand, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
392
        End Function
H
Heejae Chang 已提交
393

394
        Private Function CreateBoundUserDefinedUnaryOperatorOperation(boundUserDefinedUnaryOperator As BoundUserDefinedUnaryOperator) As IUnaryOperatorExpression
H
Heejae Chang 已提交
395 396 397 398 399 400 401 402 403 404 405 406 407
            Dim unaryOperationKind As UnaryOperationKind = Helper.DeriveUnaryOperationKind(boundUserDefinedUnaryOperator.OperatorKind)
            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)
408
            Return New LazyUnaryOperatorExpression(unaryOperationKind, operand, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
409
        End Function
H
Heejae Chang 已提交
410

411
        Private Function CreateBoundBinaryOperatorOperation(boundBinaryOperator As BoundBinaryOperator) As IBinaryOperatorExpression
H
Heejae Chang 已提交
412
            Dim binaryOperationKind As BinaryOperationKind = Helper.DeriveBinaryOperationKind(boundBinaryOperator.OperatorKind, boundBinaryOperator.Left)
H
Heejae Chang 已提交
413 414
            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 已提交
415 416 417 418 419
            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)
420
            Return New LazyBinaryOperatorExpression(binaryOperationKind, leftOperand, rightOperand, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
421
        End Function
H
Heejae Chang 已提交
422

423
        Private Function CreateBoundUserDefinedBinaryOperatorOperation(boundUserDefinedBinaryOperator As BoundUserDefinedBinaryOperator) As IBinaryOperatorExpression
H
Heejae Chang 已提交
424
            Dim binaryOperationKind As BinaryOperationKind = Helper.DeriveBinaryOperationKind(boundUserDefinedBinaryOperator.OperatorKind)
H
Heejae Chang 已提交
425 426
            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 已提交
427 428 429 430 431
            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)
432
            Return New LazyBinaryOperatorExpression(binaryOperationKind, leftOperand, rightOperand, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
433
        End Function
H
Heejae Chang 已提交
434

435
        Private Function CreateBoundBinaryConditionalExpressionOperation(boundBinaryConditionalExpression As BoundBinaryConditionalExpression) As INullCoalescingExpression
H
Heejae Chang 已提交
436 437
            Dim primaryOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryConditionalExpression.TestExpression))
            Dim secondaryOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryConditionalExpression.ElseExpression))
H
Heejae Chang 已提交
438 439 440
            Dim syntax As SyntaxNode = boundBinaryConditionalExpression.Syntax
            Dim type As ITypeSymbol = boundBinaryConditionalExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundBinaryConditionalExpression.ConstantValueOpt)
441
            Return New LazyNullCoalescingExpression(primaryOperand, secondaryOperand, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
442
        End Function
H
Heejae Chang 已提交
443

444
        Private Function CreateBoundUserDefinedShortCircuitingOperatorOperation(boundUserDefinedShortCircuitingOperator As BoundUserDefinedShortCircuitingOperator) As IBinaryOperatorExpression
H
Heejae Chang 已提交
445
            Dim binaryOperationKind As BinaryOperationKind = If((boundUserDefinedShortCircuitingOperator.BitwiseOperator.OperatorKind And BinaryOperatorKind.And) <> 0, BinaryOperationKind.OperatorMethodConditionalAnd, BinaryOperationKind.OperatorMethodConditionalOr)
H
Heejae Chang 已提交
446 447
            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 已提交
448 449 450 451 452
            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)
453
            Return New LazyBinaryOperatorExpression(binaryOperationKind, leftOperand, rightOperand, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
454
        End Function
H
Heejae Chang 已提交
455

456
        Private Function CreateBoundBadExpressionOperation(boundBadExpression As BoundBadExpression) As IInvalidExpression
H
Heejae Chang 已提交
457
            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 已提交
458 459 460
            Dim syntax As SyntaxNode = boundBadExpression.Syntax
            Dim type As ITypeSymbol = boundBadExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundBadExpression.ConstantValueOpt)
461
            Return New LazyInvalidExpression(children, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
462
        End Function
H
Heejae Chang 已提交
463

464
        Private Function CreateBoundTryCastOperation(boundTryCast As BoundTryCast) As IConversionExpression
H
Heejae Chang 已提交
465
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTryCast.Operand))
H
Heejae Chang 已提交
466 467 468 469 470 471 472
            Dim conversionKind As ConversionKind = Semantics.ConversionKind.TryCast
            Dim isExplicit As Boolean = True
            Dim usesOperatorMethod As Boolean = False
            Dim operatorMethod As IMethodSymbol = Nothing
            Dim syntax As SyntaxNode = boundTryCast.Syntax
            Dim type As ITypeSymbol = boundTryCast.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundTryCast.ConstantValueOpt)
473
            Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
474
        End Function
H
Heejae Chang 已提交
475

476
        Private Function CreateBoundDirectCastOperation(boundDirectCast As BoundDirectCast) As IConversionExpression
H
Heejae Chang 已提交
477
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDirectCast.Operand))
H
Heejae Chang 已提交
478 479 480 481 482 483 484
            Dim conversionKind As ConversionKind = Semantics.ConversionKind.Cast
            Dim isExplicit As Boolean = True
            Dim usesOperatorMethod As Boolean = False
            Dim operatorMethod As IMethodSymbol = Nothing
            Dim syntax As SyntaxNode = boundDirectCast.Syntax
            Dim type As ITypeSymbol = boundDirectCast.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundDirectCast.ConstantValueOpt)
485
            Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
486
        End Function
H
Heejae Chang 已提交
487

488
        Private Function CreateBoundConversionOperation(boundConversion As BoundConversion) As IConversionExpression
H
Heejae Chang 已提交
489
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConversion.Operand))
490
            Dim conversionKind As ConversionKind = GetConversionKind(boundConversion.ConversionKind)
H
Heejae Chang 已提交
491 492 493 494 495 496
            Dim isExplicit As Boolean = boundConversion.ExplicitCastInCode
            Dim usesOperatorMethod As Boolean = False
            Dim operatorMethod As IMethodSymbol = Nothing
            Dim syntax As SyntaxNode = boundConversion.Syntax
            Dim type As ITypeSymbol = boundConversion.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundConversion.ConstantValueOpt)
497
            Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
498
        End Function
H
Heejae Chang 已提交
499

500
        Private Function CreateBoundUserDefinedConversionOperation(boundUserDefinedConversion As BoundUserDefinedConversion) As IConversionExpression
H
Heejae Chang 已提交
501
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUserDefinedConversion.Operand))
H
Heejae Chang 已提交
502 503 504 505 506 507 508
            Dim conversionKind As ConversionKind = Semantics.ConversionKind.OperatorMethod
            Dim isExplicit As Boolean = Not boundUserDefinedConversion.WasCompilerGenerated
            Dim usesOperatorMethod As Boolean = True
            Dim operatorMethod As IMethodSymbol = boundUserDefinedConversion.Call.Method
            Dim syntax As SyntaxNode = boundUserDefinedConversion.Syntax
            Dim type As ITypeSymbol = boundUserDefinedConversion.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundUserDefinedConversion.ConstantValueOpt)
509
            Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
510
        End Function
H
Heejae Chang 已提交
511

512
        Private Function CreateBoundTernaryConditionalExpressionOperation(boundTernaryConditionalExpression As BoundTernaryConditionalExpression) As IConditionalChoiceExpression
H
Heejae Chang 已提交
513 514 515
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.Condition))
            Dim ifTrueValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.WhenTrue))
            Dim ifFalseValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.WhenFalse))
H
Heejae Chang 已提交
516 517 518
            Dim syntax As SyntaxNode = boundTernaryConditionalExpression.Syntax
            Dim type As ITypeSymbol = boundTernaryConditionalExpression.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundTernaryConditionalExpression.ConstantValueOpt)
519
            Return New LazyConditionalChoiceExpression(condition, ifTrueValue, ifFalseValue, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
520
        End Function
H
Heejae Chang 已提交
521

522
        Private Function CreateBoundTypeOfOperation(boundTypeOf As BoundTypeOf) As IIsTypeExpression
H
Heejae Chang 已提交
523
            Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTypeOf.Operand))
H
Heejae Chang 已提交
524 525 526 527
            Dim isType As ITypeSymbol = boundTypeOf.TargetType
            Dim syntax As SyntaxNode = boundTypeOf.Syntax
            Dim type As ITypeSymbol = boundTypeOf.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundTypeOf.ConstantValueOpt)
528
            Return New LazyIsTypeExpression(operand, isType, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
529
        End Function
H
Heejae Chang 已提交
530

531
        Private Function CreateBoundObjectCreationExpressionOperation(boundObjectCreationExpression As BoundObjectCreationExpression) As IObjectCreationExpression
H
Heejae Chang 已提交
532
            Dim constructor As IMethodSymbol = boundObjectCreationExpression.ConstructorOpt
533
            Dim memberInitializers As Lazy(Of IObjectOrCollectionInitializerExpression) = New Lazy(Of IObjectOrCollectionInitializerExpression)(
H
Heejae Chang 已提交
534
                Function()
535
                    Return DirectCast(Create(boundObjectCreationExpression.InitializerOpt), IObjectOrCollectionInitializerExpression)
H
Heejae Chang 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548
                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)
549
            Return New LazyObjectCreationExpression(constructor, memberInitializers, argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
550
        End Function
H
Heejae Chang 已提交
551

552 553 554 555 556
        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)
557
            Return New LazyObjectOrCollectionInitializerExpression(initializers, _semanticModel, syntax, type, constantValue)
558 559 560 561 562 563 564
        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)
565
            Return New LazyObjectOrCollectionInitializerExpression(initializers, _semanticModel, syntax, type, constantValue)
566 567 568
        End Function

        Private Function CreateBoundCollectionElementInitializerOperation(boundExpression As BoundExpression) As IOperation
M
Manish Vasani 已提交
569
            If boundExpression.Kind <> BoundKind.Call Then
570 571 572 573 574 575 576 577 578 579
                ' 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)
580
            Return New LazyCollectionElementInitializerExpression(addMethod, arguments, isDynamic, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
581
        End Function
H
Heejae Chang 已提交
582

583
        Private Function CreateBoundNewTOperation(boundNewT As BoundNewT) As ITypeParameterObjectCreationExpression
584
            Dim initializer As Lazy(Of IObjectOrCollectionInitializerExpression) = New Lazy(Of IObjectOrCollectionInitializerExpression)(Function() DirectCast(Create(boundNewT.InitializerOpt), IObjectOrCollectionInitializerExpression))
H
Heejae Chang 已提交
585 586 587
            Dim syntax As SyntaxNode = boundNewT.Syntax
            Dim type As ITypeSymbol = boundNewT.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundNewT.ConstantValueOpt)
H
Heejae Chang 已提交
588
            Return New LazyTypeParameterObjectCreationExpression(initializer, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
589
        End Function
H
Heejae Chang 已提交
590

591
        Private Function CreateBoundArrayCreationOperation(boundArrayCreation As BoundArrayCreation) As IArrayCreationExpression
592
            Dim elementType As ITypeSymbol = TryCast(boundArrayCreation.Type, IArrayTypeSymbol)?.ElementType
H
Heejae Chang 已提交
593
            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 已提交
594 595 596 597
            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)
598
            Return New LazyArrayCreationExpression(elementType, dimensionSizes, initializer, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
599
        End Function
H
Heejae Chang 已提交
600

601
        Private Function CreateBoundArrayInitializationOperation(boundArrayInitialization As BoundArrayInitialization) As IArrayInitializer
H
Heejae Chang 已提交
602
            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 已提交
603 604 605
            Dim syntax As SyntaxNode = boundArrayInitialization.Syntax
            Dim type As ITypeSymbol = boundArrayInitialization.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundArrayInitialization.ConstantValueOpt)
606
            Return New LazyArrayInitializer(elementValues, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
607
        End Function
H
Heejae Chang 已提交
608

609
        Private Function CreateBoundPropertyAccessOperation(boundPropertyAccess As BoundPropertyAccess) As IPropertyReferenceExpression
H
Heejae Chang 已提交
610 611 612 613 614 615 616 617 618 619
            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
620 621 622 623 624 625
            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 已提交
626 627 628
            Dim syntax As SyntaxNode = boundPropertyAccess.Syntax
            Dim type As ITypeSymbol = boundPropertyAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundPropertyAccess.ConstantValueOpt)
629
            Return New LazyPropertyReferenceExpression([property], instance, [property], argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
630
        End Function
H
Heejae Chang 已提交
631

632
        Private Function CreateBoundEventAccessOperation(boundEventAccess As BoundEventAccess) As IEventReferenceExpression
H
Heejae Chang 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
                    If boundEventAccess.EventSymbol.IsShared Then
                        Return Nothing
                    Else
                        Return Create(boundEventAccess.ReceiverOpt)
                    End If
                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)
646
            Return New LazyEventReferenceExpression([event], instance, [event], _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
647
        End Function
H
Heejae Chang 已提交
648

649
        Private Function CreateBoundFieldAccessOperation(boundFieldAccess As BoundFieldAccess) As IFieldReferenceExpression
H
Heejae Chang 已提交
650 651 652 653 654 655
            Dim field As IFieldSymbol = boundFieldAccess.FieldSymbol
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
                    If boundFieldAccess.FieldSymbol.IsShared Then
                        Return Nothing
                    Else
H
Heejae Chang 已提交
656
                        Return Create(boundFieldAccess.ReceiverOpt)
H
Heejae Chang 已提交
657 658 659 660 661 662 663
                    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)
664
            Return New LazyFieldReferenceExpression(field, instance, member, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
665
        End Function
H
Heejae Chang 已提交
666

667
        Private Function CreateBoundConditionalAccessOperation(boundConditionalAccess As BoundConditionalAccess) As IConditionalAccessExpression
H
Heejae Chang 已提交
668 669
            Dim conditionalValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConditionalAccess.AccessExpression))
            Dim conditionalInstance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConditionalAccess.Receiver))
H
Heejae Chang 已提交
670 671 672
            Dim syntax As SyntaxNode = boundConditionalAccess.Syntax
            Dim type As ITypeSymbol = boundConditionalAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundConditionalAccess.ConstantValueOpt)
673
            Return New LazyConditionalAccessExpression(conditionalValue, conditionalInstance, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
674
        End Function
H
Heejae Chang 已提交
675

676
        Private Function CreateBoundConditionalAccessReceiverPlaceholderOperation(boundConditionalAccessReceiverPlaceholder As BoundConditionalAccessReceiverPlaceholder) As IConditionalAccessInstanceExpression
H
Heejae Chang 已提交
677 678 679
            Dim syntax As SyntaxNode = boundConditionalAccessReceiverPlaceholder.Syntax
            Dim type As ITypeSymbol = boundConditionalAccessReceiverPlaceholder.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundConditionalAccessReceiverPlaceholder.ConstantValueOpt)
680
            Return New ConditionalAccessInstanceExpression(_semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
681
        End Function
H
Heejae Chang 已提交
682

683
        Private Function CreateBoundParameterOperation(boundParameter As BoundParameter) As IParameterReferenceExpression
H
Heejae Chang 已提交
684 685 686 687
            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)
688
            Return New ParameterReferenceExpression(parameter, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
689
        End Function
H
Heejae Chang 已提交
690

691
        Private Function CreateBoundLocalOperation(boundLocal As BoundLocal) As ILocalReferenceExpression
H
Heejae Chang 已提交
692 693 694 695
            Dim local As ILocalSymbol = boundLocal.LocalSymbol
            Dim syntax As SyntaxNode = boundLocal.Syntax
            Dim type As ITypeSymbol = boundLocal.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLocal.ConstantValueOpt)
696
            Return New LocalReferenceExpression(local, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
697
        End Function
H
Heejae Chang 已提交
698

699
        Private Function CreateBoundLateMemberAccessOperation(boundLateMemberAccess As BoundLateMemberAccess) As IDynamicMemberReferenceExpression
H
Heejae Chang 已提交
700
            Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundLateMemberAccess.ReceiverOpt))
H
Heejae Chang 已提交
701
            Dim memberName As String = boundLateMemberAccess.NameOpt
702 703 704 705
            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
706 707 708 709 710 711 712 713 714 715
            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 已提交
716 717 718
            Dim syntax As SyntaxNode = boundLateMemberAccess.Syntax
            Dim type As ITypeSymbol = boundLateMemberAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundLateMemberAccess.ConstantValueOpt)
H
Heejae Chang 已提交
719
            Return New LazyDynamicMemberReferenceExpression(instance, memberName, typeArguments, containingType, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
720
        End Function
H
Heejae Chang 已提交
721

722
        Private Function CreateBoundFieldInitializerOperation(boundFieldInitializer As BoundFieldInitializer) As IFieldInitializer
H
Heejae Chang 已提交
723
            Dim initializedFields As ImmutableArray(Of IFieldSymbol) = ImmutableArray(Of IFieldSymbol).CastUp(boundFieldInitializer.InitializedFields)
H
Heejae Chang 已提交
724
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundFieldInitializer.InitialValue))
725
            Dim kind As OperationKind = OperationKind.FieldInitializer
H
Heejae Chang 已提交
726 727 728
            Dim syntax As SyntaxNode = boundFieldInitializer.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
729
            Return New LazyFieldInitializer(initializedFields, value, kind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
730
        End Function
H
Heejae Chang 已提交
731

732
        Private Function CreateBoundPropertyInitializerOperation(boundPropertyInitializer As BoundPropertyInitializer) As IPropertyInitializer
H
Heejae Chang 已提交
733
            Dim initializedProperty As IPropertySymbol = boundPropertyInitializer.InitializedProperties.FirstOrDefault()
H
Heejae Chang 已提交
734
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundPropertyInitializer.InitialValue))
735
            Dim kind As OperationKind = OperationKind.PropertyInitializer
H
Heejae Chang 已提交
736 737 738
            Dim syntax As SyntaxNode = boundPropertyInitializer.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
739
            Return New LazyPropertyInitializer(initializedProperty, value, kind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
740
        End Function
H
Heejae Chang 已提交
741

742
        Private Function CreateBoundParameterEqualsValueOperation(boundParameterEqualsValue As BoundParameterEqualsValue) As IParameterInitializer
H
Heejae Chang 已提交
743
            Dim parameter As IParameterSymbol = boundParameterEqualsValue.Parameter
H
Heejae Chang 已提交
744
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundParameterEqualsValue.Value))
745
            Dim kind As OperationKind = OperationKind.ParameterInitializer
H
Heejae Chang 已提交
746 747 748
            Dim syntax As SyntaxNode = boundParameterEqualsValue.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
749
            Return New LazyParameterInitializer(parameter, value, kind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
750
        End Function
H
Heejae Chang 已提交
751

752
        Private Function CreateBoundRValuePlaceholderOperation(boundRValuePlaceholder As BoundRValuePlaceholder) As IPlaceholderExpression
H
Heejae Chang 已提交
753 754 755
            Dim syntax As SyntaxNode = boundRValuePlaceholder.Syntax
            Dim type As ITypeSymbol = boundRValuePlaceholder.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundRValuePlaceholder.ConstantValueOpt)
756
            Return New PlaceholderExpression(_semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
757
        End Function
H
Heejae Chang 已提交
758

759
        Private Function CreateBoundIfStatementOperation(boundIfStatement As BoundIfStatement) As IIfStatement
H
Heejae Chang 已提交
760 761 762
            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 已提交
763 764 765
            Dim syntax As SyntaxNode = boundIfStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
766
            Return New LazyIfStatement(condition, ifTrueStatement, ifFalseStatement, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
767
        End Function
H
Heejae Chang 已提交
768

769
        Private Function CreateBoundSelectStatementOperation(boundSelectStatement As BoundSelectStatement) As ISwitchStatement
H
Heejae Chang 已提交
770
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSelectStatement.ExpressionStatement.Expression))
771
            Dim cases As Lazy(Of ImmutableArray(Of ISwitchCase)) = New Lazy(Of ImmutableArray(Of ISwitchCase))(Function() GetSwitchStatementCases(boundSelectStatement.CaseBlocks))
H
Heejae Chang 已提交
772 773 774
            Dim syntax As SyntaxNode = boundSelectStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
775
            Return New LazySwitchStatement(value, cases, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
776
        End Function
H
Heejae Chang 已提交
777

778
        Private Function CreateBoundSimpleCaseClauseOperation(boundSimpleCaseClause As BoundSimpleCaseClause) As ISingleValueCaseClause
779 780 781
            Dim clauseValue = GetSingleValueCaseClauseValue(boundSimpleCaseClause)
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(clauseValue))
            Dim equality As BinaryOperationKind = GetSingleValueCaseClauseEquality(clauseValue)
H
Heejae Chang 已提交
782 783 784 785
            Dim caseKind As CaseKind = CaseKind.SingleValue
            Dim syntax As SyntaxNode = boundSimpleCaseClause.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
786
            Return New LazySingleValueCaseClause(value, equality, caseKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
787
        End Function
H
Heejae Chang 已提交
788

789
        Private Function CreateBoundRangeCaseClauseOperation(boundRangeCaseClause As BoundRangeCaseClause) As IRangeCaseClause
H
Heejae Chang 已提交
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
            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)
                        If lowerBound.OperatorKind = BinaryOperatorKind.GreaterThanOrEqual Then
                            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)
                        If upperBound.OperatorKind = BinaryOperatorKind.LessThanOrEqual Then
                            Return Create(upperBound.Right)
                        End If
                    End If

                    Return Nothing
                End Function)
            Dim caseKind As CaseKind = CaseKind.Range
            Dim syntax As SyntaxNode = boundRangeCaseClause.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
824
            Return New LazyRangeCaseClause(minimumValue, maximumValue, caseKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
825
        End Function
H
Heejae Chang 已提交
826

827
        Private Function CreateBoundRelationalCaseClauseOperation(boundRelationalCaseClause As BoundRelationalCaseClause) As IRelationalCaseClause
H
Heejae Chang 已提交
828 829
            Dim valueExpression = GetRelationalCaseClauseValue(boundRelationalCaseClause)
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(valueExpression))
H
Heejae Chang 已提交
830
            Dim relation As BinaryOperationKind = If(valueExpression IsNot Nothing, Helper.DeriveBinaryOperationKind(boundRelationalCaseClause.OperatorKind, valueExpression), BinaryOperationKind.Invalid)
H
Heejae Chang 已提交
831 832 833 834
            Dim caseKind As CaseKind = CaseKind.Relational
            Dim syntax As SyntaxNode = boundRelationalCaseClause.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
835
            Return New LazyRelationalCaseClause(value, relation, caseKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
836
        End Function
H
Heejae Chang 已提交
837

838
        Private Function CreateBoundDoLoopStatementOperation(boundDoLoopStatement As BoundDoLoopStatement) As IWhileUntilLoopStatement
H
Heejae Chang 已提交
839 840
            Dim isTopTest As Boolean = boundDoLoopStatement.ConditionIsTop
            Dim isWhile As Boolean = Not boundDoLoopStatement.ConditionIsUntil
H
Heejae Chang 已提交
841
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDoLoopStatement.ConditionOpt))
H
Heejae Chang 已提交
842
            Dim loopKind As LoopKind = LoopKind.WhileUntil
H
Heejae Chang 已提交
843
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDoLoopStatement.Body))
H
Heejae Chang 已提交
844 845 846
            Dim syntax As SyntaxNode = boundDoLoopStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
847
            Return New LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, loopKind, body, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
848
        End Function
H
Heejae Chang 已提交
849

850
        Private Function CreateBoundForToStatementOperation(boundForToStatement As BoundForToStatement) As IForLoopStatement
851 852
            Dim before As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
853 854 855 856 857
                    Return GetForLoopStatementBefore(
                        boundForToStatement.ControlVariable,
                        boundForToStatement.InitialValue,
                        Create(boundForToStatement.LimitValue).Clone(),
                        Create(boundForToStatement.StepValue).Clone())
858 859 860
                End Function)
            Dim atLoopBottom As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
861 862 863 864
                    Return GetForLoopStatementAtLoopBottom(
                        Create(boundForToStatement.ControlVariable).Clone(),
                        boundForToStatement.StepValue,
                        boundForToStatement.OperatorsOpt)
865
                End Function)
H
Heejae Chang 已提交
866
            Dim locals As ImmutableArray(Of ILocalSymbol) = ImmutableArray(Of ILocalSymbol).Empty
867 868
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(
                Function()
869 870 871 872 873
                    Return GetForWhileUntilLoopStatementCondition(
                        boundForToStatement.ControlVariable,
                        boundForToStatement.LimitValue,
                        boundForToStatement.StepValue,
                        boundForToStatement.OperatorsOpt)
874
                End Function)
H
Heejae Chang 已提交
875
            Dim loopKind As LoopKind = LoopKind.For
H
Heejae Chang 已提交
876
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundForToStatement.Body))
H
Heejae Chang 已提交
877 878 879
            Dim syntax As SyntaxNode = boundForToStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
880
            Return New LazyForLoopStatement(before, atLoopBottom, locals, condition, loopKind, body, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
881
        End Function
H
Heejae Chang 已提交
882

883
        Private Function CreateBoundForEachStatementOperation(boundForEachStatement As BoundForEachStatement) As IForEachLoopStatement
H
Heejae Chang 已提交
884
            Dim iterationVariable As ILocalSymbol = Nothing ' Manual
H
Heejae Chang 已提交
885
            Dim collection As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundForEachStatement.Collection))
H
Heejae Chang 已提交
886
            Dim loopKind As LoopKind = LoopKind.ForEach
H
Heejae Chang 已提交
887
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundForEachStatement.Body))
H
Heejae Chang 已提交
888 889 890
            Dim syntax As SyntaxNode = boundForEachStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
891
            Return New LazyForEachLoopStatement(iterationVariable, collection, loopKind, body, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
892
        End Function
H
Heejae Chang 已提交
893

894
        Private Function CreateBoundTryStatementOperation(boundTryStatement As BoundTryStatement) As ITryStatement
H
Heejae Chang 已提交
895
            Dim body As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundTryStatement.TryBlock), IBlockStatement))
H
Heejae Chang 已提交
896
            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 已提交
897 898 899 900
            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)()
901
            Return New LazyTryStatement(body, catches, finallyHandler, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
902
        End Function
H
Heejae Chang 已提交
903

904
        Private Function CreateBoundCatchBlockOperation(boundCatchBlock As BoundCatchBlock) As ICatchClause
H
Heejae Chang 已提交
905 906
            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 已提交
907
            Dim filter As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundCatchBlock.ExceptionFilterOpt))
H
Heejae Chang 已提交
908 909 910 911
            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)()
912
            Return New LazyCatchClause(handler, caughtType, filter, exceptionLocal, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
913
        End Function
H
Heejae Chang 已提交
914

915
        Private Function CreateBoundBlockOperation(boundBlock As BoundBlock) As IBlockStatement
916 917 918 919
            Dim statements As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(
                Function()
                    Return boundBlock.Statements.Select(Function(n) Create(n)).Where(Function(s) s.Kind <> OperationKind.None).ToImmutableArray()
                End Function)
H
Heejae Chang 已提交
920 921 922 923
            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)()
924
            Return New LazyBlockStatement(statements, locals, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
925
        End Function
H
Heejae Chang 已提交
926

927
        Private Function CreateBoundBadStatementOperation(boundBadStatement As BoundBadStatement) As IInvalidStatement
H
Heejae Chang 已提交
928 929 930 931 932 933 934 935 936 937 938 939
            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 已提交
940 941 942
            Dim syntax As SyntaxNode = boundBadStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
943
            Return New LazyInvalidStatement(children, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
944
        End Function
H
Heejae Chang 已提交
945

946
        Private Function CreateBoundReturnStatementOperation(boundReturnStatement As BoundReturnStatement) As IReturnStatement
H
Heejae Chang 已提交
947
            Dim returnedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundReturnStatement.ExpressionOpt))
H
Heejae Chang 已提交
948 949 950
            Dim syntax As SyntaxNode = boundReturnStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
951
            Return New LazyReturnStatement(OperationKind.ReturnStatement, returnedValue, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
952
        End Function
H
Heejae Chang 已提交
953

954
        Private Function CreateBoundThrowStatementOperation(boundThrowStatement As BoundThrowStatement) As IThrowStatement
H
Heejae Chang 已提交
955
            Dim thrownObject As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundThrowStatement.ExpressionOpt))
H
Heejae Chang 已提交
956 957 958
            Dim syntax As SyntaxNode = boundThrowStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
959
            Return New LazyThrowStatement(thrownObject, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
960
        End Function
H
Heejae Chang 已提交
961

962
        Private Function CreateBoundWhileStatementOperation(boundWhileStatement As BoundWhileStatement) As IWhileUntilLoopStatement
H
Heejae Chang 已提交
963 964
            Dim isTopTest As Boolean = True
            Dim isWhile As Boolean = True
H
Heejae Chang 已提交
965
            Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWhileStatement.Condition))
H
Heejae Chang 已提交
966
            Dim loopKind As LoopKind = LoopKind.WhileUntil
H
Heejae Chang 已提交
967
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWhileStatement.Body))
H
Heejae Chang 已提交
968 969 970
            Dim syntax As SyntaxNode = boundWhileStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
971
            Return New LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, loopKind, body, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
972
        End Function
H
Heejae Chang 已提交
973

974
        Private Function CreateBoundDimStatementOperation(boundDimStatement As BoundDimStatement) As IVariableDeclarationStatement
H
Heejae Chang 已提交
975
            Dim declarations As Lazy(Of ImmutableArray(Of IVariableDeclaration)) = New Lazy(Of ImmutableArray(Of IVariableDeclaration))(Function() GetVariableDeclarationStatementVariables(boundDimStatement))
H
Heejae Chang 已提交
976 977 978
            Dim syntax As SyntaxNode = boundDimStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
979
            Return New LazyVariableDeclarationStatement(declarations, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
980
        End Function
H
Heejae Chang 已提交
981

982
        Private Function CreateBoundYieldStatementOperation(boundYieldStatement As BoundYieldStatement) As IReturnStatement
H
Heejae Chang 已提交
983
            Dim returnedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundYieldStatement.Expression))
H
Heejae Chang 已提交
984 985 986
            Dim syntax As SyntaxNode = boundYieldStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
987
            Return New LazyReturnStatement(OperationKind.YieldReturnStatement, returnedValue, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
988
        End Function
H
Heejae Chang 已提交
989

990
        Private Function CreateBoundLabelStatementOperation(boundLabelStatement As BoundLabelStatement) As ILabelStatement
H
Heejae Chang 已提交
991
            Dim label As ILabelSymbol = boundLabelStatement.Label
992
            Dim labeledStatement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Nothing)
H
Heejae Chang 已提交
993 994 995
            Dim syntax As SyntaxNode = boundLabelStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
996
            Return New LazyLabelStatement(label, labeledStatement, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
997
        End Function
H
Heejae Chang 已提交
998

999
        Private Function CreateBoundGotoStatementOperation(boundGotoStatement As BoundGotoStatement) As IBranchStatement
H
Heejae Chang 已提交
1000 1001 1002 1003 1004
            Dim target As ILabelSymbol = boundGotoStatement.Label
            Dim branchKind As BranchKind = BranchKind.GoTo
            Dim syntax As SyntaxNode = boundGotoStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1005
            Return New BranchStatement(target, branchKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1006
        End Function
H
Heejae Chang 已提交
1007

1008
        Private Function CreateBoundContinueStatementOperation(boundContinueStatement As BoundContinueStatement) As IBranchStatement
H
Heejae Chang 已提交
1009 1010 1011 1012 1013
            Dim target As ILabelSymbol = boundContinueStatement.Label
            Dim branchKind As BranchKind = BranchKind.Continue
            Dim syntax As SyntaxNode = boundContinueStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1014
            Return New BranchStatement(target, branchKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1015
        End Function
H
Heejae Chang 已提交
1016

1017
        Private Function CreateBoundExitStatementOperation(boundExitStatement As BoundExitStatement) As IBranchStatement
H
Heejae Chang 已提交
1018 1019 1020 1021 1022
            Dim target As ILabelSymbol = boundExitStatement.Label
            Dim branchKind As BranchKind = BranchKind.Break
            Dim syntax As SyntaxNode = boundExitStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1023
            Return New BranchStatement(target, branchKind, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1024
        End Function
H
Heejae Chang 已提交
1025

1026
        Private Function CreateBoundSyncLockStatementOperation(boundSyncLockStatement As BoundSyncLockStatement) As ILockStatement
H
Heejae Chang 已提交
1027 1028
            Dim lockedObject As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSyncLockStatement.LockExpression))
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSyncLockStatement.Body))
H
Heejae Chang 已提交
1029 1030 1031
            Dim syntax As SyntaxNode = boundSyncLockStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1032
            Return New LazyLockStatement(lockedObject, body, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1033
        End Function
H
Heejae Chang 已提交
1034

1035
        Private Function CreateBoundNoOpStatementOperation(boundNoOpStatement As BoundNoOpStatement) As IEmptyStatement
H
Heejae Chang 已提交
1036 1037 1038
            Dim syntax As SyntaxNode = boundNoOpStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1039
            Return New EmptyStatement(_semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1040
        End Function
H
Heejae Chang 已提交
1041

1042
        Private Function CreateBoundStopStatementOperation(boundStopStatement As BoundStopStatement) As IStopStatement
H
Heejae Chang 已提交
1043 1044 1045
            Dim syntax As SyntaxNode = boundStopStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1046
            Return New StopStatement(_semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1047
        End Function
H
Heejae Chang 已提交
1048

1049
        Private Function CreateBoundEndStatementOperation(boundEndStatement As BoundEndStatement) As IEndStatement
H
Heejae Chang 已提交
1050 1051 1052
            Dim syntax As SyntaxNode = boundEndStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1053
            Return New EndStatement(_semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1054
        End Function
H
Heejae Chang 已提交
1055

1056
        Private Function CreateBoundWithStatementOperation(boundWithStatement As BoundWithStatement) As IWithStatement
H
Heejae Chang 已提交
1057 1058
            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 已提交
1059 1060 1061
            Dim syntax As SyntaxNode = boundWithStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1062
            Return New LazyWithStatement(body, value, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1063
        End Function
H
Heejae Chang 已提交
1064

1065
        Private Function CreateBoundUsingStatementOperation(boundUsingStatement As BoundUsingStatement) As IUsingStatement
H
Heejae Chang 已提交
1066
            Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUsingStatement.Body))
1067 1068 1069 1070
            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 已提交
1071
            Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUsingStatement.ResourceExpressionOpt))
H
Heejae Chang 已提交
1072 1073 1074
            Dim syntax As SyntaxNode = boundUsingStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1075
            Return New LazyUsingStatement(body, declaration, value, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1076
        End Function
H
Heejae Chang 已提交
1077

1078
        Private Function CreateBoundExpressionStatementOperation(boundExpressionStatement As BoundExpressionStatement) As IExpressionStatement
H
Heejae Chang 已提交
1079
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundExpressionStatement.Expression))
H
Heejae Chang 已提交
1080 1081 1082
            Dim syntax As SyntaxNode = boundExpressionStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1083
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1084
        End Function
H
Heejae Chang 已提交
1085

1086
        Private Function CreateBoundRaiseEventStatementOperation(boundRaiseEventStatement As BoundRaiseEventStatement) As IExpressionStatement
H
Heejae Chang 已提交
1087
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundRaiseEventStatement.EventInvocation))
H
Heejae Chang 已提交
1088 1089 1090
            Dim syntax As SyntaxNode = boundRaiseEventStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1091
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1092
        End Function
H
Heejae Chang 已提交
1093

1094
        Private Function CreateBoundAddHandlerStatementOperation(boundAddHandlerStatement As BoundAddHandlerStatement) As IExpressionStatement
H
Heejae Chang 已提交
1095
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetAddHandlerStatementExpression(boundAddHandlerStatement))
H
Heejae Chang 已提交
1096 1097 1098
            Dim syntax As SyntaxNode = boundAddHandlerStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1099
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1100
        End Function
H
Heejae Chang 已提交
1101

1102
        Private Function CreateBoundRemoveHandlerStatementOperation(boundRemoveHandlerStatement As BoundRemoveHandlerStatement) As IExpressionStatement
H
Heejae Chang 已提交
1103
            Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetRemoveStatementExpression(boundRemoveHandlerStatement))
H
Heejae Chang 已提交
1104 1105 1106
            Dim syntax As SyntaxNode = boundRemoveHandlerStatement.Syntax
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
1107
            Return New LazyExpressionStatement(expression, _semanticModel, syntax, type, constantValue)
H
Heejae Chang 已提交
1108
        End Function
1109

1110 1111
        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)))
1112 1113
            Dim syntax As SyntaxNode = boundTupleExpression.Syntax
            Dim type As ITypeSymbol = boundTupleExpression.Type
1114
            Dim constantValue As [Optional](Of Object) = Nothing
1115
            Return New LazyTupleExpression(elements, _semanticModel, syntax, type, constantValue)
1116
        End Function
1117

1118
        Private Function CreateBoundInterpolatedStringExpressionOperation(boundInterpolatedString As BoundInterpolatedStringExpression) As IInterpolatedStringExpression
1119 1120 1121 1122 1123
            Dim parts As New Lazy(Of ImmutableArray(Of IInterpolatedStringContent))(
                Function()
                    Return boundInterpolatedString.Contents.SelectAsArray(Function(interpolatedStringContent) CreateBoundInterpolatedStringContentOperation(interpolatedStringContent))
                End Function)

1124 1125 1126
            Dim syntax As SyntaxNode = boundInterpolatedString.Syntax
            Dim type As ITypeSymbol = boundInterpolatedString.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundInterpolatedString.ConstantValueOpt)
1127
            Return New LazyInterpolatedStringExpression(parts, _semanticModel, syntax, type, constantValue)
1128 1129
        End Function

1130
        Private Function CreateBoundInterpolatedStringContentOperation(boundNode As BoundNode) As IInterpolatedStringContent
M
Manish Vasani 已提交
1131
            If boundNode.Kind = BoundKind.Interpolation Then
M
Manish Vasani 已提交
1132
                Return DirectCast(Create(boundNode), IInterpolatedStringContent)
M
Manish Vasani 已提交
1133 1134
            Else
                Return CreateBoundInterpolatedStringTextOperation(boundNode)
1135 1136 1137
            End If
        End Function

1138
        Private Function CreateBoundInterpolationOperation(boundInterpolation As BoundInterpolation) As IInterpolation
1139 1140 1141 1142 1143 1144
            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
1145
            Return New LazyInterpolation(expression, alignment, format, _semanticModel, syntax, type, constantValue)
1146 1147
        End Function

1148
        Private Function CreateBoundInterpolatedStringTextOperation(boundNode As BoundNode) As IInterpolatedStringText
M
Manish Vasani 已提交
1149 1150
            Dim text As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundNode))
            Dim syntax As SyntaxNode = boundNode.Syntax
1151 1152
            Dim type As ITypeSymbol = Nothing
            Dim constantValue As [Optional](Of Object) = Nothing
1153
            Return New LazyInterpolatedStringText(text, _semanticModel, syntax, type, constantValue)
1154
        End Function
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164

        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)
1165
            Return New LazyAnonymousObjectCreationExpression(initializers, _semanticModel, syntax, type, constantValue)
1166 1167 1168 1169 1170
        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 已提交
1171
            Dim argumentsInEvaluationOrder As Lazy(Of ImmutableArray(Of IArgument)) = New Lazy(Of ImmutableArray(Of IArgument))(Function() ImmutableArray(Of IArgument).Empty)
1172 1173 1174
            Dim syntax As SyntaxNode = boundAnonymousTypePropertyAccess.Syntax
            Dim type As ITypeSymbol = boundAnonymousTypePropertyAccess.Type
            Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundAnonymousTypePropertyAccess.ConstantValueOpt)
1175
            Return New LazyPropertyReferenceExpression([property], instance, [property], argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue)
1176
        End Function
H
Heejae Chang 已提交
1177 1178 1179 1180
    End Class
End Namespace