Exemplo n.º 1
0
                public override bool Unary(APC pc, UnaryOperator op, bool overflow, bool unsigned, Variable dest, Variable source, bool data)
                {
                    if (this.IgnoreProofObligationAtPC(pc))
                    {
                        return(data);
                    }

                    var mdDecoder = this.MetaDataDecoder;

                    if (this.myOptions.NegMinObligations && op == UnaryOperator.Neg)
                    {
                        var type = this.Context.ValueContext.GetType(pc, source);
                        if (type.IsNormal &&
                            (mdDecoder.Equal(type.Value, mdDecoder.System_Int32) ||
                             mdDecoder.Equal(type.Value, mdDecoder.System_Int64) ||
                             mdDecoder.Equal(type.Value, mdDecoder.System_Int16) ||
                             mdDecoder.Equal(type.Value, mdDecoder.System_Int8)
                            ))
                        {
                            var argAsBoxedExpression = BoxedExpression.Convert(this.Context.ExpressionContext.Refine(pc, source), this.DecoderForExpressions.Outdecoder);
                            if (argAsBoxedExpression != null)
                            {
                                this.Add(new NoMinValueObligation(type.Value, mdDecoder.Name(type.Value), argAsBoxedExpression, this.DecoderForExpressions, pc, this.MethodDriver));
                            }
                        }
                    }

                    if (overflow && this.myOptions.ArithmeticOverflow && op.IsConversionOperator())
                    {
                        // this.Context.ValueContext.GetType fails sometimes. This is why we infer the type from the operator
                        Type type;
                        if (mdDecoder.TryInferTypeForOperator(op, out type))
                        {
                            var exp = BoxedExpression.Convert(this.Context.ExpressionContext.Refine(pc, source), this.DecoderForExpressions.Outdecoder);

                            if (exp != null)
                            {
                                this.Add(new ArithmeticUnderflow(exp, type, pc, this.DecoderForExpressions, this.MethodDriver));
                                this.Add(new ArithmeticOverflow(exp, type, pc, this.DecoderForExpressions, this.MethodDriver));
                            }
                        }
                    }

                    return(data);
                }