public void TestIsInstance() { Assert.False(ParenthesizedVariableDesignationSyntaxWrapper.IsInstance(null)); Assert.False(ParenthesizedVariableDesignationSyntaxWrapper.IsInstance(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))); var syntaxNode = SyntaxFactory.ParenthesizedVariableDesignation(); Assert.True(ParenthesizedVariableDesignationSyntaxWrapper.IsInstance(syntaxNode)); }
static int GetTupleCount(ExpressionSyntax assignmentLeft) { var result = 0; if (TupleExpressionSyntaxWrapper.IsInstance(assignmentLeft)) { result = ((TupleExpressionSyntaxWrapper)assignmentLeft).Arguments.Count; } else if (DeclarationExpressionSyntaxWrapper.IsInstance(assignmentLeft) && (DeclarationExpressionSyntaxWrapper)assignmentLeft is { } leftDeclaration && ParenthesizedVariableDesignationSyntaxWrapper.IsInstance(leftDeclaration.Designation)) { result = ((ParenthesizedVariableDesignationSyntaxWrapper)leftDeclaration.Designation).Variables.Count; } return(result); }
private ProgramState VisitVariableDesignation(VariableDesignationSyntaxWrapper variableDesignation, ProgramState programState, bool singleVariable) { var newProgramState = programState; if (DiscardDesignationSyntaxWrapper.IsInstance(variableDesignation)) { // Push value for the discard, it will be popped when visiting the block for the // corresponding case statement. newProgramState = newProgramState.PushValue(SymbolicValue.Create()); } else if (SingleVariableDesignationSyntaxWrapper.IsInstance(variableDesignation)) { // "x is string s" is equivalent to "s = x"; both symbolic values should remain on stack var singleVariableDesignation = (SingleVariableDesignationSyntaxWrapper)variableDesignation; // associate variable with new SV var variableSymbol = SemanticModel.GetDeclaredSymbol(singleVariableDesignation); var newSymbolicValue = SymbolicValue.Create(); newProgramState = SetNewSymbolicValueIfTracked(variableSymbol, newSymbolicValue, newProgramState); if (singleVariable) { // When the pattern is "x is Type t" we know that "t != null", hence (SV != null) newProgramState = newProgramState.PushValue(new ValueNotEqualsSymbolicValue(newSymbolicValue, SymbolicValue.Null)); } } else if (ParenthesizedVariableDesignationSyntaxWrapper.IsInstance(variableDesignation)) { var parenthesizedVariableDesignation = (ParenthesizedVariableDesignationSyntaxWrapper)variableDesignation; foreach (var variable in parenthesizedVariableDesignation.Variables) { // the variables in the deconstruction should not receive "Not Null" constraint newProgramState = VisitVariableDesignation(variable, newProgramState, singleVariable: false); } } else { throw new NotSupportedException($"{variableDesignation.SyntaxNode.Kind()}"); } return(newProgramState); }