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); } } } } }
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 } }