' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports Microsoft.CodeAnalysis.Semantics Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Roslyn.Test.Utilities Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics Partial Public Class IOperationTests Inherits SemanticModelTestBase Public Sub IWhileUntilLoopStatement_DoWhileLoopsTest() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of DoLoopBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileConditionTrue() Dim source = 10 Then condition = False End If End While End Sub End Class ]]>.Value Dim expectedOperationTree = ... End If') Condition: IBinaryOperatorExpression (BinaryOperationKind.IntegerGreaterThan) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'value > 10') Left: ILocalReferenceExpression: value (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'value') Right: ILiteralExpression (Text: 10) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10) (Syntax: '10') IfTrue: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: 'If value > ... End If') IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'condition = False') Expression: ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Boolean) (Syntax: 'condition = False') Left: ILocalReferenceExpression: condition (OperationKind.LocalReferenceExpression, Type: System.Boolean) (Syntax: 'condition') Right: ILiteralExpression (Text: False) (OperationKind.LiteralExpression, Type: System.Boolean, Constant: False) (Syntax: 'False') IfFalse: null ]]>.Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileLoopsTest() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithBreak() Dim source = 5 Then System.Console.WriteLine("While-loop break") Exit While End If System.Console.WriteLine("While-loop statement") End While End Sub End Class ]]>.Value Dim expectedOperationTree = ... End If') Condition: IBinaryOperatorExpression (BinaryOperationKind.IntegerGreaterThan) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'value > 5') Left: ILocalReferenceExpression: value (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'value') Right: ILiteralExpression (Text: 5) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 5) (Syntax: '5') IfTrue: IBlockStatement (2 statements) (OperationKind.BlockStatement) (Syntax: 'If value > ... End If') IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'System.Cons ... oop break")') Expression: IInvocationExpression (Sub System.Console.WriteLine(value As System.String)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'System.Cons ... oop break")') Instance Receiver: null Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: '"While-loop break"') ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: "While-loop break") (Syntax: '"While-loop break"') InConversion: null OutConversion: null IBranchStatement (BranchKind.Break, Label: exit) (OperationKind.BranchStatement) (Syntax: 'Exit While') IfFalse: null IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'System.Cons ... statement")') Expression: IInvocationExpression (Sub System.Console.WriteLine(value As System.String)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'System.Cons ... statement")') Instance Receiver: null Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: '"While-loop statement"') ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: "While-loop statement") (Syntax: '"While-loop statement"') InConversion: null OutConversion: null ]]>.Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithThrow() Dim source = 100 Then Throw New System.Exception("An exception has occurred.") End If System.Console.WriteLine("While-loop statement") End While End Sub End Class ]]>.Value Dim expectedOperationTree = ... End If') Condition: IBinaryOperatorExpression (BinaryOperationKind.IntegerGreaterThan) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'value > 100') Left: ILocalReferenceExpression: value (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'value') Right: ILiteralExpression (Text: 100) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 100) (Syntax: '100') IfTrue: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: 'If value > ... End If') IThrowStatement (OperationKind.ThrowStatement) (Syntax: 'Throw New S ... occurred.")') ThrownObject: IObjectCreationExpression (Constructor: Sub System.Exception..ctor(message As System.String)) (OperationKind.ObjectCreationExpression, Type: System.Exception) (Syntax: 'New System. ... occurred.")') Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: message) (OperationKind.Argument) (Syntax: '"An excepti ... occurred."') ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: "An exception has occurred.") (Syntax: '"An excepti ... occurred."') InConversion: null OutConversion: null Initializer: null IfFalse: null IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'System.Cons ... statement")') Expression: IInvocationExpression (Sub System.Console.WriteLine(value As System.String)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'System.Cons ... statement")') Instance Receiver: null Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: '"While-loop statement"') ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: "While-loop statement") (Syntax: '"While-loop statement"') InConversion: null OutConversion: null ]]>.Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithAssignment() Dim source = = 0'BIND:"While (InlineAssignHelper(i, value)) >= 0" System.Console.WriteLine("While {0} {1}", i, value) value -= 1 End While End Sub Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T target = value Return value End Function End Class ]]>.Value Dim expectedOperationTree = = 0') Left: IParenthesizedExpression (OperationKind.ParenthesizedExpression, Type: System.Int32) (Syntax: '(InlineAssi ... (i, value))') Operand: IInvocationExpression (Function Program.InlineAssignHelper(Of System.Int32)(ByRef target As System.Int32, value As System.Int32) As System.Int32) (OperationKind.InvocationExpression, Type: System.Int32) (Syntax: 'InlineAssig ... r(i, value)') Instance Receiver: null Arguments(2): IArgument (ArgumentKind.Explicit, Matching Parameter: target) (OperationKind.Argument) (Syntax: 'i') ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'i') InConversion: null OutConversion: null IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: 'value') ILocalReferenceExpression: value (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'value') InConversion: null OutConversion: null Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0') Body: IBlockStatement (2 statements) (OperationKind.BlockStatement) (Syntax: 'While (Inli ... End While') IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'System.Cons ... , i, value)') Expression: IInvocationExpression (Sub System.Console.WriteLine(format As System.String, arg0 As System.Object, arg1 As System.Object)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'System.Cons ... , i, value)') Instance Receiver: null Arguments(3): IArgument (ArgumentKind.Explicit, Matching Parameter: format) (OperationKind.Argument) (Syntax: '"While {0} {1}"') ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: "While {0} {1}") (Syntax: '"While {0} {1}"') InConversion: null OutConversion: null IArgument (ArgumentKind.Explicit, Matching Parameter: arg0) (OperationKind.Argument) (Syntax: 'i') IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'i') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'i') InConversion: null OutConversion: null IArgument (ArgumentKind.Explicit, Matching Parameter: arg1) (OperationKind.Argument) (Syntax: 'value') IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'value') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: ILocalReferenceExpression: value (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'value') InConversion: null OutConversion: null IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'value -= 1') Expression: ICompoundAssignmentExpression (BinaryOperationKind.IntegerSubtract) (OperationKind.CompoundAssignmentExpression, Type: System.Int32) (Syntax: 'value -= 1') Left: ILocalReferenceExpression: value (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'value') Right: ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1') ]]>.Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileImplicit() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithReturn() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithGoto() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileMissingCondition() Dim source = 100 Then condition = False End If End While End Sub End Class ]]>.Value Dim expectedOperationTree = ... End If') Condition: IBinaryOperatorExpression (BinaryOperationKind.IntegerGreaterThan) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'value > 100') Left: ILocalReferenceExpression: value (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'value') Right: ILiteralExpression (Text: 100) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 100) (Syntax: '100') IfTrue: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: 'If value > ... End If') IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'condition = False') Expression: ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Boolean) (Syntax: 'condition = False') Left: ILocalReferenceExpression: condition (OperationKind.LocalReferenceExpression, Type: System.Boolean) (Syntax: 'condition') Right: ILiteralExpression (Text: False) (OperationKind.LiteralExpression, Type: System.Boolean, Constant: False) (Syntax: 'False') IfFalse: null ]]>.Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileMissingStatement() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithContinue() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileConditionInVocationExpression() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileNested() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileChangeOuterInnerValue() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileIncrementInCondition() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileInfiniteLoop() Dim source = 0'BIND:"While i > 0" i += 1 End While End Sub End Class ]]>.Value Dim expectedOperationTree = 0 ... End While') Condition: IBinaryOperatorExpression (BinaryOperationKind.IntegerGreaterThan) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'i > 0') Left: ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'i') Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0') Body: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: 'While i > 0 ... End While') IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'i += 1') Expression: ICompoundAssignmentExpression (BinaryOperationKind.IntegerAdd) (OperationKind.CompoundAssignmentExpression, Type: System.Int32) (Syntax: 'i += 1') Left: ILocalReferenceExpression: i (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'i') Right: ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1') ]]>.Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileConstantCheck() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithTryCatch() Dim source = 0'BIND:"While System.Math.Max(System.Threading.Interlocked.Decrement(x), x + 1) > 0" Try y = CSByte(x / 2) Finally Throw New System.Exception() End Try End While End Sub End Class ]]>.Value Dim expectedOperationTree = 0') Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: IBinaryOperatorExpression (BinaryOperationKind.Invalid) (OperationKind.BinaryOperatorExpression, Type: ?, IsInvalid) (Syntax: 'System.Math ... x + 1) > 0') Left: IInvalidExpression (OperationKind.InvalidExpression, Type: ?, IsInvalid) (Syntax: 'System.Math ... (x), x + 1)') Children(3): IOperation: (OperationKind.None) (Syntax: 'System.Math.Max') IInvalidExpression (OperationKind.InvalidExpression, Type: ?, IsInvalid) (Syntax: 'System.Thre ... ecrement(x)') Children(2): IOperation: (OperationKind.None, IsInvalid) (Syntax: 'System.Thre ... d.Decrement') ILocalReferenceExpression: x (OperationKind.LocalReferenceExpression, Type: System.SByte) (Syntax: 'x') IBinaryOperatorExpression (BinaryOperationKind.IntegerAdd) (OperationKind.BinaryOperatorExpression, Type: System.Int32) (Syntax: 'x + 1') Left: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Int32) (Syntax: 'x') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: True, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: ILocalReferenceExpression: x (OperationKind.LocalReferenceExpression, Type: System.SByte) (Syntax: 'x') Right: ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1') Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0') Body: IBlockStatement (1 statements) (OperationKind.BlockStatement, IsInvalid) (Syntax: 'While Syste ... End While') ITryStatement (OperationKind.TryStatement) (Syntax: 'Try ... End Try') Body: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: 'Try ... End Try') IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'y = CSByte(x / 2)') Expression: ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.SByte) (Syntax: 'y = CSByte(x / 2)') Left: ILocalReferenceExpression: y (OperationKind.LocalReferenceExpression, Type: System.SByte) (Syntax: 'y') Right: IConversionExpression (Explicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.SByte) (Syntax: 'CSByte(x / 2)') Conversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: IBinaryOperatorExpression (BinaryOperationKind.FloatingDivide) (OperationKind.BinaryOperatorExpression, Type: System.Double) (Syntax: 'x / 2') Left: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Double) (Syntax: 'x') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: True, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: ILocalReferenceExpression: x (OperationKind.LocalReferenceExpression, Type: System.SByte) (Syntax: 'x') Right: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Double, Constant: 2) (Syntax: '2') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: True, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: ILiteralExpression (Text: 2) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: '2') Catch clauses(0) Finally: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: 'Finally ... Exception()') IThrowStatement (OperationKind.ThrowStatement) (Syntax: 'Throw New S ... Exception()') ThrownObject: IObjectCreationExpression (Constructor: Sub System.Exception..ctor()) (OperationKind.ObjectCreationExpression, Type: System.Exception) (Syntax: 'New System.Exception()') Arguments(0) Initializer: null ]]>.Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_DoWhileFuncCall() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of DoLoopBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_DoLoopWhileStatement() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of DoLoopBlockSyntax)(source, expectedOperationTree) End Sub Public Sub IWhileUntilLoopStatement_WhileWithNot() Dim source = .Value Dim expectedOperationTree = .Value VerifyOperationTreeForTest(Of WhileBlockSyntax)(source, expectedOperationTree) End Sub End Class End Namespace