public override bool SuggestAnalysisSpecificPostconditions(
     ContractInferenceManager inferenceManager,
     IFixpointInfo <APC, ArrayState> fixpointInfo,
     List <BoxedExpression> postconditions)
 {
     return(false);
 }
Ejemplo n.º 2
0
 public override bool SuggestAnalysisSpecificPostconditions(
     ContractInferenceManager inferenceManager,
     IFixpointInfo <APC, EnumDefined <BoxedVariable <Variable>, Type, BoxedExpression> > fixpointInfo,
     List <BoxedExpression> postconditions)
 {
     return(false);
 }
Ejemplo n.º 3
0
                    public EnumFactQuery(EnumAnalysis analysis, IFixpointInfo <APC, EnumDefined <BoxedVariable <Variable>, Type, BoxedExpression> > fixpoint)
                    {
                        Contract.Requires(analysis != null);

                        this.analysis = analysis;
                        this.fixpoint = fixpoint;
                    }
                    public ArrayExpressionRefinementFactQuery(ArrayExpressionRefinementPlugIn analysis, IFixpointInfo <APC, ArrayState> fixpoint)
                    {
                        Contract.Requires(analysis != null);
                        Contract.Requires(fixpoint != null);

                        this.fixpoint = fixpoint;
                        this.analysis = analysis;
                    }
                    public EnumPlugingFactQuery(EnumAnalysisWrapperPlugIn analysis, IFixpointInfo <APC, ArrayState> fixpoint)
                    {
                        Contract.Requires(analysis != null);
                        Contract.Requires(fixpoint != null);

                        this.analysis = analysis;
                        this.fixpoint = fixpoint;
                    }
                public ArrayPurityFactQuery(ArrayPurityAnalysisPlugIn analysis, IFixpointInfo <APC, ArrayState> fixpoint)
                {
                    Contract.Requires(analysis != null);
                    Contract.Requires(fixpoint != null);

                    this.fixpoint = fixpoint;
                    this.analysis = analysis;
                }
Ejemplo n.º 7
0
                    public RuntimeTypesFactQuery(RuntimeTypesPlugIn analysis, IFixpointInfo <APC, ArrayState> fixpoint)
                    {
                        Contract.Requires(analysis != null);
                        Contract.Requires(fixpoint != null);

                        this.analysis = analysis;
                        this.fixpoint = fixpoint;
                    }
Ejemplo n.º 8
0
                public override IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, INumericalAbstractDomain <BoxedVariable <Variable>, BoxedExpression> > fixpoint)
                {
                    if (this.optionsList.Count <= 1 || this.HasSwitchedToAdaptativeMode)
                    {
#if DEBUG
                        // Just for tracing
                        if (this.optionsList.Count > 1)
                        {
                            Console.WriteLine(string.Format("Skipped numerical domain refinement. Reason: We are running an adaptive analysis"));
                        }
#endif
                        return(new AILogicInference <INumericalAbstractDomain <BoxedVariable <Variable>, BoxedExpression> >(this.Decoder,
                                                                                                                            this.Options, fixpoint, this.Context, this.DecoderForMetaData, this.Options.TraceChecks));
                    }
                    else
                    {
                        return(new AILogicInferenceWithRefinements <INumericalAbstractDomain <BoxedVariable <Variable>, BoxedExpression> >(this.Decoder,
                                                                                                                                           this.Options, fixpoint, this.Context, this.DecoderForMetaData, FixpointInfo, this.Options.TraceChecks));
                    }
                }
Ejemplo n.º 9
0
        MyDomain GetReturnState <MyDomain>(IFixpointInfo <APC, MyDomain> fixpoint, IAbstractAnalysis <Local, Parameter, Method, Field, Property, Type, Expression, Attribute, Assembly, MyDomain, Variable> analysis, int state, out bool isBottom, MyDomain defaultValue)
        {
            MyDomain returnState = defaultValue;
            var      fakeEdge    = new Pair <APC, APC>(driver.CFG.NormalExit, driver.CFG.Entry);

            if (stateInfo.StateReturnPoints == null || !stateInfo.StateReturnPoints.ContainsKey(state))
            {
                isBottom = true;
            }
            else
            {
                bool first = true;
                isBottom = true;
                foreach (APC returnPoint in stateInfo.StateReturnPoints[state])
                {
                    MyDomain tmp;
                    if (fixpoint.PostState(returnPoint, out tmp) && !analysis.IsBottom(returnPoint, tmp))
                    {
                        isBottom = false;
                        var edge = new Pair <APC, APC>(returnPoint, driver.CFG.Entry.Post());
                        IFunctionalMap <Variable, FList <Variable> > mapping = GetFieldMapping(driver, returnPoint, driver.CFG.Entry.Post());
                        MyDomain newState = analysis.EdgeConversion(fakeEdge.One, fakeEdge.Two, true, mapping, tmp);
                        bool     ignore;
                        if (first)
                        {
                            returnState = newState;
                            first       = false;
                        }
                        else
                        {
                            returnState = analysis.Join(edge, newState, returnState, out ignore, false);
                        }
                    }
                }
            }
            return(returnState);
        }
Ejemplo n.º 10
0
 public override IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> > fixpoint)
 {
     return(new SimpleLogicInference <Local, Parameter, Method, Field, Type, Expression, Variable>(this.Context,
                                                                                                   new FactBase(fixpoint), null, null, this.MethodDriver.BasicFacts.IsUnreachable, null));
 }
Ejemplo n.º 11
0
 public FactBase(IFixpointInfo <APC, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> > fixpoint)
 {
     this.fixpoint = fixpoint;
 }
Ejemplo n.º 12
0
 public override bool SuggestAnalysisSpecificPostconditions(ContractInferenceManager inferenceManager, IFixpointInfo <APC, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> > fixpointInfo, List <BoxedExpression> postconditions)
 {
     // does nothing
     return(false);
 }
Ejemplo n.º 13
0
 public override bool TrySuggestPostconditionForOutParameters(IFixpointInfo <APC, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> > fixpointInfo, List <BoxedExpression> postconditions, Variable p, FList <PathElement> path)
 {
     return(false);
 }
                public override void SuggestPrecondition(ContractInferenceManager inferenceManager, IFixpointInfo <APC, ArrayState> fixpointinfo)
                {
                    Contract.Assume(inferenceManager != null, "Assume for inheritance");

                    if (
                        !this.Options.LogOptions.SuggestRequiresPurityForArrays &&
                        !this.Options.LogOptions.PropagateRequiresPurityForArrays)
                    {
                        return;
                    }

                    ArrayState returnState;

                    if (PreState(this.Context.MethodContext.CFG.NormalExit, fixpointinfo, out returnState))
                    {
                        Contract.Assume(returnState != null);
                        var mySubState = Select(returnState);

#pragma warning disable 0219
                        var first = true; // used in the commented part below
#pragma warning restore

                        foreach (var element in mySubState.Elements)
                        {
#if false // Make it true to debug the content of the result state
                            if (ContainsUnModifiedSegment(element.Value))
                            {
                                if (first)
                                {
                                    Console.WriteLine("Method: {0}", this.Context.MethodContext.CurrentMethod);
                                    first = false;
                                }

                                var arrayName = this.VariablesToPrettyNames(this.Context.MethodContext.CFG.EntryAfterRequires, element.Key);
                                if (arrayName != null)
                                {
                                    var preconditions = element.Value.PrettyPrint(
                                        arrayName,
                                        (var => this.VariablesToPrettyNames(this.Context.MethodContext.CFG.EntryAfterRequires, var)),
                                        (ael => this.PrettyPrint(arrayName, ael))
                                        );
                                    foreach (var str in preconditions)
                                    {
                                        output.WriteLine("Effect on the input array segment: {0}", str);
                                    }
                                }
                            }
#endif
                            var exp = ToBoxedExpression(this.Context.MethodContext.CFG.Entry, element.Key);
                            var pre = PreconditionSuggestion.ExpressionInPreState(exp, this.Context,
                                                                                  this.DecoderForMetaData, this.Context.MethodContext.CFG.EntryAfterRequires,
                                                                                  allowedKinds: ExpressionInPreStateKind.MethodPrecondition);

                            Contract.Assume(element.Value != null);

                            if (pre != null &&
                                AllSegmentsUnmodified(element.Value) &&
                                !this.DecoderForContracts.IsPure(this.Context.MethodContext.CurrentMethod)
                                )
                            {
                                Parameter p;
                                int       pos;
                                Contract.Assume(element.Key != null, "Assuming the precondition");
                                if (TryParameterFor(element.Key, out p, out pos) && !this.DecoderForMetaData.IsPure(this.Context.MethodContext.CurrentMethod, p))
                                {
                                    // TODO: wire those suggestions to the contract inference manager
                                    if (this.Options.LogOptions.SuggestRequiresPurityForArrays)
                                    {
                                        inferenceManager.Output.Suggestion(ClousotSuggestion.Kind.Requires, ClousotSuggestion.Kind.Requires.Message(), this.Context.MethodContext.CFG.EntryAfterRequires,
                                                                           string.Format("Consider adding the [Pure] attribute to the parameter {0}", pre.ToString()), null, ClousotSuggestion.ExtraSuggestionInfo.None);
                                    }

                                    if (this.Options.LogOptions.PropagateRequiresPurityForArrays && pos <= 64)
                                    {
                                        this.DecoderForMetaData.AddPure(this.Context.MethodContext.CurrentMethod, pos);
                                    }
                                }
                            }
                        }
                    }
                }
Ejemplo n.º 15
0
            public Predicate <APC> CacheStates(IFixpointInfo <APC, AbstractValue> fixpointInfo)
            {
                this.fixpointInfo = fixpointInfo;

                return((APC pc) => false);
            }
 public override bool SuggestAnalysisSpecificPostconditions(ContractInferenceManager inferenceManager, IFixpointInfo <APC, DisjunctiveRefinement> fixpointInfo, List <BoxedExpression> postconditions)
 {
     // does nothing
     return(false);
 }
Ejemplo n.º 17
0
 public override IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, ArrayState> fixpoint)
 {
     return(null);
 }
 public override IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, DisjunctiveRefinement> fixpoint)
 {
     return(null);
 }
 public override bool TrySuggestPostconditionForOutParameters(IFixpointInfo <APC, DisjunctiveRefinement> fixpointInfo, List <BoxedExpression> postconditions, Variable p, FList <PathElement> path)
 {
     // does nothing
     return(false);
 }
 virtual public void SuggestPrecondition(ContractInferenceManager inferenceManager, IFixpointInfo <APC, ArrayState> fixpointInfo)
 {
     // does nothing by default
 }
 public override bool TrySuggestPostconditionForOutParameters(
     IFixpointInfo <APC, ArrayState> fixpointInfo, List <BoxedExpression> postconditions, Variable p, FList <PathElement> path)
 {
     return(false);
 }
Ejemplo n.º 22
0
 public override IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, INumericalAbstractDomain <BoxedVariable <Variable>, BoxedExpression> > fixpoint)
 {
     return(new AILogicInference <INumericalAbstractDomain <BoxedVariable <Variable>, BoxedExpression> >(this.Decoder,
                                                                                                         this.Options, fixpoint, this.Context, this.DecoderForMetaData, this.Options.TraceNumericalAnalysis));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// This method is called by the underlying driver of the fixpoint computation. It provides delegates for future lookup
 /// of the abstract state at given pcs.
 /// </summary>
 /// <returns>Return true only if you want the fixpoint computation to eagerly cache each pc state.</returns>
 public Predicate <APC> CacheStates(IFixpointInfo <APC, Domain> fixpointInfo)
 {
     return(default(Predicate <APC>));
 }
Ejemplo n.º 24
0
 public IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, Data <Variable> > fixpoint)
 {
     return(null);
 }
Ejemplo n.º 25
0
 public override IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, EnumDefined <BoxedVariable <Variable>, Type, BoxedExpression> > fixpoint)
 {
     return(new EnumFactQuery(this, fixpoint));
 }
Ejemplo n.º 26
0
 public Predicate <APC> CacheStates(IFixpointInfo <APC, Data <Variable> > fixpointInfo)
 {
     return(apc => false);
 }
Ejemplo n.º 27
0
 public override bool TrySuggestPostconditionForOutParameters(IFixpointInfo <APC, EnumDefined <BoxedVariable <Variable>, Type, BoxedExpression> > fixpointInfo, List <BoxedExpression> postconditions, Variable p, FList <PathElement> path)
 {
     return(false);
 }
Ejemplo n.º 28
0
 public Predicate <APC> CacheStates(IFixpointInfo <APC, bool> fixpointInfo)
 {
     return(null);
 }
 public override IFactQuery <BoxedExpression, Variable> FactQuery(IFixpointInfo <APC, ArrayState> fixpoint)
 {
     return(new EnumPlugingFactQuery(this, fixpoint));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// This method is called by the underlying driver of the fixpoint computation. It provides delegates for future lookup
 /// of the abstract state at given pcs.
 /// </summary>
 /// <returns>Return true only if you want the fixpoint computation to eagerly cache each pc state.</returns>
 public Predicate <APC> CacheStates(IFixpointInfo <APC, INumericalAbstractDomain <BoxedVariable <Variable>, BoxedExpression> > fixpointInfo)
 {
     return(PCsAtBranches);
 }