Example #1
0
        public override AccessorOrMutator VisitAssignmentExpression(AssignmentExpressionSyntax node)
        {
            // C# evaluates subexpressions from left to right and so do we
            var left  = Visit(node.Left);
            var right = Visit(node.Right);

            switch (node.Kind())
            {
            case SyntaxKind.SimpleAssignmentExpression:
            {
                var leftAccessor = left as Accessor;
                if (leftAccessor != null)
                {
                    return(leftAccessor.AcceptAssignment(this, right.GetMutator(this)));
                }
                break;
            }

            case SyntaxKind.AddAssignmentExpression:
            case SyntaxKind.SubtractAssignmentExpression:
            case SyntaxKind.MultiplyAssignmentExpression:
            case SyntaxKind.DivideAssignmentExpression:
            case SyntaxKind.ModuloAssignmentExpression:
            case SyntaxKind.AndAssignmentExpression:
            case SyntaxKind.OrAssignmentExpression:
            {
                var leftAccessor = left as Accessor;
                if (leftAccessor != null)
                {
                    var methodSymbol = Model.GetSymbolInfo(node).Symbol as IMethodSymbol;
                    if (methodSymbol != null)
                    {
                        // The method symbols seem to always be the same as in the non-assignment case
                        var result = Lifter.LiftStaticNonVoidBinaryMethod(methodSymbol)(left.GetMutator(this), right.GetMutator(this));
                        return(leftAccessor.AcceptAssignment(this, result));
                    }
                }
                break;
            }
            }
            throw new SyntaxErrorException("Unsupported syntax: " + node);
        }
Example #2
0
        public override AccessorOrMutator VisitBinaryExpression(BinaryExpressionSyntax node)
        {
            // C# evaluates subexpressions from left to right and so do we
            var left  = Visit(node.Left);
            var right = Visit(node.Right);

            switch (node.Kind())
            {
            case SyntaxKind.AddExpression:
            case SyntaxKind.SubtractExpression:
            case SyntaxKind.MultiplyExpression:
            case SyntaxKind.DivideExpression:
            case SyntaxKind.ModuloExpression:
            case SyntaxKind.BitwiseAndExpression:
            case SyntaxKind.BitwiseOrExpression:
            case SyntaxKind.ExclusiveOrExpression:
            case SyntaxKind.EqualsExpression:
            case SyntaxKind.NotEqualsExpression:
            case SyntaxKind.GreaterThanExpression:
            case SyntaxKind.LessThanExpression:
            case SyntaxKind.GreaterThanOrEqualExpression:
            case SyntaxKind.LessThanOrEqualExpression:
            case SyntaxKind.LeftShiftExpression:
            case SyntaxKind.RightShiftExpression:
            {
                var methodSymbol = Model.GetSymbolInfo(node).Symbol as IMethodSymbol;
                if (methodSymbol != null)
                {
                    return(Lifter.LiftStaticNonVoidBinaryMethod(methodSymbol)(left.GetMutator(this), right.GetMutator(this)));
                }
                break;
            }

            case SyntaxKind.LogicalAndExpression:
            case SyntaxKind.LogicalOrExpression:
                // TODO: Implement short cirquiting. This should probably be done as a transformation on
                // the CFG which makes sure that short cirquiting operations never end up here.
                throw new SymbolicExplorationException("Short circuiting logical operators are not supported");
            }
            throw new SyntaxErrorException("Unsupported syntax: " + node);
        }