public override IExpression VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node)
        {
            var            o       = this.semanticModel.GetTypeInfo(node);
            var            t       = this.mapper.Map(o.Type);
            var            operand = this.Visit(node.Operand);
            UnaryOperation op      = null;

            switch (node.Kind)
            {
            case SyntaxKind.BitwiseNotExpression:
                op = new OnesComplement();
                break;

            case SyntaxKind.UnaryMinusExpression:
                op      = new UnaryNegation();
                op.Type = operand.Type;
                break;

            case SyntaxKind.PreDecrementExpression:
            case SyntaxKind.PreIncrementExpression:
                BinaryOperation bo;
                if (node.OperatorToken.Kind == SyntaxKind.MinusMinusToken)
                {
                    bo = new Subtraction();
                }
                else
                {
                    bo = new Addition();
                }
                object one = GetConstantOneOfMatchingTypeForIncrementDecrement(operand.Type.ResolvedType); // REVIEW: Do we really need to resolve?
                bo.LeftOperand  = operand;
                bo.RightOperand = new CompileTimeConstant()
                {
                    Type = operand.Type, Value = one,
                };
                bo.Type = operand.Type;
                var assign = new Assignment()
                {
                    Source = bo,
                    Target = Helper.MakeTargetExpression(operand),
                    Type   = operand.Type,
                };
                return(assign);

            case SyntaxKind.LogicalNotExpression:
                op = new LogicalNot();
                break;

            default:
                var typeName = node.GetType().ToString();
                var msg      = String.Format("Was unable to convert a {0} node to CCI because the kind '{1}' wasn't handled",
                                             typeName, node.Kind.ToString());
                throw new ConverterException(msg);
            }
            op.Operand = operand;
            return(op);
        }
            private IExpression ReplaceOperation <T>(T operation) where T : IExpression
            {
                var mcall = operation as MethodCall;

                if (mcall != null)
                {
                    if (mcall.MethodToCall.Name.Value == "Abs")
                    {
                        return(operation);
                    }
                }


                if (MutationTarget.PassInfo.IsIn("Abs", "NegAbs"))
                {
                    INamedTypeDefinition systemConsole = UnitHelper.FindType(NameTable, CoreAssembly, "System.Math");
                    IMethodDefinition    abs           = TypeHelper.GetMethod(systemConsole, NameTable.GetNameFor("Abs"), operation.Type);

                    var call = new MethodCall
                    {
                        IsStaticCall = true,
                        MethodToCall = abs,
                        Type         = abs.Type
                    };
                    call.Arguments.Add(operation);

                    IExpression result = call;

                    if (MutationTarget.PassInfo == "NegAbs")
                    {
                        result = new UnaryNegation
                        {
                            CheckOverflow = false,
                            Operand       = call,
                            Type          = operation.Type,
                        };
                    }
                    return(result);
                }
                else
                {
                    INamedTypeDefinition systemConsole = UnitHelper.FindType(NameTable, Module, "VisualMutatorGeneratedClass");
                    IMethodDefinition    failOnZero    = (IMethodDefinition)systemConsole.GetMembersNamed(NameTable.GetNameFor("FailOnZero"), false).Single();
                    var call = new MethodCall
                    {
                        IsStaticCall = true,
                        MethodToCall = failOnZero,
                        Type         = failOnZero.Type
                    };
                    call.Arguments.Add(operation);
                    return(call);
                }
            }
Example #3
0
        public override Expression VisitUnaryExpression([NotNull] RheaParser.UnaryExpressionContext context)
        {
            Unary node;

            switch (context.op.Type)
            {
            // FIXME: WTF?
            case RheaLexer.OP_ADD:
            case RheaLexer.OP_SUB:
                node = new UnaryNegation();
                break;

            default:
                throw new NotImplementedException();
            }

            node.ParentBlock = parentBlock;
            node.Expression  = Visit(context.expression());

            return(node);
        }
Example #4
0
 public static T Negative <T>(T value)
 => UnaryNegation <T, T> .Invoke(value);
Example #5
0
 public static R Negative <T, R>(T value)
 => UnaryNegation <T, R> .Invoke(value);