Пример #1
0
            public override IProofObligations <Variable, BoxedExpression> GetProofObligations <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable>
            (
                string fullMethodName,
                IMethodDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ILogOptions> mdriver
            )
            {
                var obl = new ProofObligationComposition <Variable, BoxedExpression>();

                if (!this.boundsOptions[0].NoProofObligations)
                {
                    var numObl = new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .BoundsObligations(mdriver, this.boundsOptions[0].NoProofObligations);

                    obl.Add(numObl);
                }
                if (this.nonnullAnalysis != null)
                {
                    var nnObl = this.nonnullAnalysis.GetProofObligations(fullMethodName, mdriver);
                    if (nnObl != null)
                    {
                        obl.Add(nnObl);
                    }
                }
                if (this.IsEnumAnalysisSelected)
                {
                    obl.Add(new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .EnumObligations(mdriver, false));
                }

                return(obl);
            }
Пример #2
0
            public override IProofObligations <Variable, BoxedExpression> GetProofObligations <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable>(string fullMethodName, IMethodDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ILogOptions> mdriver)
            {
                var result =
                    new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .BoundsObligations(mdriver, this.options[0].NoProofObligations);

                return(result);
            }
            public void SuggestContractsForExtractedMethod(Preconditions postConditionsAsBE, IOutput output)
            {
                IEnumerable <BoxedExpression> newPreconditions;

                if (this.TryInferPreconditionsFromPostconditions(postConditionsAsBE.ToList(), out newPreconditions))
                {
                    var decompiler = new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .BooleanExpressionsDecompiler <LogOptions>(this.MDriver);

                    var alreadyShown = new Set <string>();

                    foreach (var p in newPreconditions)
                    {
                        var             inPreState = PreconditionSuggestion.ExpressionInPreState(p, this.MDriver.Context, this.MDriver.MetaDataDecoder, this.MDriver.CFG.EntryAfterRequires, allowedKinds: ExpressionInPreStateKind.MethodPrecondition);
                        BoxedExpression decompiled;
                        if (inPreState != null && decompiler.FixIt(this.MDriver.CFG.EntryAfterRequires, inPreState.expr, out decompiled))
                        {
                            var outStr = decompiled.ToString();
                            if (this.Facts.IsTrue(this.MDriver.CFG.EntryAfterRequires, decompiled) == ProofOutcome.Top && !alreadyShown.Contains(outStr))
                            {
                                output.Suggestion(ClousotSuggestion.Kind.Requires, ClousotSuggestion.Kind.Requires.Message(),
                                                  this.MDriver.CFG.Entry, string.Format("Extract method suggestion: Contract.Requires({0});", outStr), null, ClousotSuggestion.ExtraSuggestionInfo.None);
                                alreadyShown.Add(outStr);
                            }
                        }
                    }
                }
            }
Пример #4
0
            public override T Instantiate <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, T>
            (
                string methodName,
                IMethodDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ILogOptions> mdriver,
                Predicate <APC> cachePCs,
                IMethodAnalysisClientFactory <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, T> factory, DFAController controller
            )
            {
                var numericalAnalysis =
                    new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .
                    NumericalAnalysis <Bounds.BoundsOptions>(methodName, mdriver, this.boundsOptions, cachePCs, controller);

                var nonnullAnalysis =
                    this.nonnullAnalysis != null ?
                    new Analyzers.NonNull.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .
                    AnalysisForArrays(mdriver, this.nonnullAnalysis, cachePCs)
          : null;

                var arrayAnalysis =
                    new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .
                    ArrayAnalysisPlugIn(methodName, mdriver, this.options[0].LogOptions, cachePCs);

                var analysis =
                    new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .
                    ArrayAnalysis <Analyzers.Arrays.ArrayOptions, Bounds.BoundsOptions>(methodName, arrayAnalysis, numericalAnalysis, nonnullAnalysis, this.IsEnumAnalysisSelected, mdriver, this.options[0], cachePCs);

                return(factory.Create(analysis, controller));
            }
                private ExpressionManager <BoxedVariable <Variable>, BoxedExpression> GetExpressionManager()
                {
                    var valuedDecoder = new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .ValueExpDecoder(this.Mdriver.Context, this.Mdriver.MetaDataDecoder);

                    var expDecoder = BoxedExpressionDecoder <Variable> .Decoder(valuedDecoder, (object o) => ExpressionType.Unknown);

                    var expEncoder = BoxedExpressionEncoder <Variable> .Encoder(this.Mdriver.MetaDataDecoder, this.Mdriver.Context);

                    var expManager = new ExpressionManagerWithEncoder <BoxedVariable <Variable>, BoxedExpression>(this.timeout, expDecoder, expEncoder);

                    return(expManager);
                }
Пример #6
0
            public override T Instantiate <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, T>(
                string methodName,
                IMethodDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ILogOptions> driver,
                Predicate <APC> cachePCs,
                IMethodAnalysisClientFactory <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, T> factory
                )
            {
                var analysis = new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .
                               StringValueAnalysis(methodName, driver, options[0], cachePCs);

                return(factory.Create(analysis));
            }
Пример #7
0
            public override T Instantiate <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, T>(
                string methodName,
                IMethodDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ILogOptions> driver,
                Predicate <APC> cachePCs,
                IMethodAnalysisClientFactory <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, T> factory, DFAController controller
                )
            {
                var adomain  = options[0].Type;
                var analysis = new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .ArithmeticAnalysis(methodName, driver, options[0], adomain, cachePCs, controller);

                return(factory.Create(analysis, controller));
            }
Пример #8
0
            override public bool ExecuteAbstractDomainFunctor <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, Options, Result, Data>(
                IClassDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, Options, IMethodResult <Variable> > cdriver,
                IResultsFunctor <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, Result, Data> functor,
                Data data,
                out Result result)
            //where Variable : IEquatable<Variable>
            //where Expression : IEquatable<Expression>
            //where Type : IEquatable<Type>
            //where Options : IFrameworkLogOptions
            {
                var aoi = new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .AbstractOperationsImplementationNumerical <Bounds.BoundsOptions>();

                return(functor.Execute(aoi, data, out result));
            }
        private BoxedExpression SimplifyAndFix(APC pc, BoxedExpression precondition)
        {
            Contract.Requires(precondition != null);

            var decompiler = new AnalysisWrapper.TypeBindings <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable> .BooleanExpressionsDecompiler <LogOptions>(mdriver);

            BoxedExpression result;

            if (decompiler.FixIt(pc, precondition, out result))
            {
                return(result.Simplify(this.mdriver.MetaDataDecoder));
            }
            else
            {
                return(null); // doesn't type check and is not fixable, ignore
            }
        }