/// <summary> /// Represents method which is used for confirming assumption condition. Assumption can be declined - it means that we can prove, that condition CANNOT be ever satisfied. /// </summary> /// <returns>False if you can prove that condition cannot be ever satisfied, true otherwise.</returns> public override bool ConfirmAssumption(FlowOutputSet outSet, AssumptionCondition condition, EvaluationLog log) { _outSet = outSet; _log = log; bool willAssume; switch (condition.Form) { case ConditionForm.All: willAssume = needsAll(outSet.Snapshot, condition.Parts); break; case ConditionForm.None: //willAssume = needsNone(outSet.Snapshot, condition.Parts); //break; case ConditionForm.SomeNot: willAssume = needsSomeNot(outSet.Snapshot, condition.Parts); break; default: //we has to assume, because we can't disprove assumption willAssume = true; break; } if (willAssume) { processAssumption(condition); } return(willAssume); }
/// <summary> /// Represents method which is used for confirming assumption condition. Assumption can be declined - it means that we can prove, that condition CANNOT be ever satisfied. /// </summary> /// <param name="outSet">Output set where condition will be assumed</param> /// <param name="condition">Assumed condition</param> /// <param name="log">The evaluation log of the code constructs.</param> /// <returns> /// <c>false</c> if condition cannot be ever satisfied, true otherwise. /// </returns> public override bool ConfirmAssumption(FlowOutputSet outSet, AssumptionCondition condition, EvaluationLog log) { // Deprecated code that supported assumptions that are not decomposed using logical operators (&&, ||, xor) // But it had very limited abstract state refinemend /* * AssumptionConditionExecuterDepr conditionParts = new AssumptionConditionExecuterDepr(condition.Form, outSet, log, condition.Parts); * return conditionParts.MakeAssumption(null); */ // Non-primitive conditions in assumptions are now resolved on the level of control-flow graph PHP.Core.Debug.Assert(condition.Parts.Count() == 1); PHP.Core.Debug.Assert(condition.Form == ConditionForm.All || condition.Form == ConditionForm.None); var assumptionExecuter = new AssumptionExecuter(condition.Form, condition.Parts.First().SourceElement, log, outSet); AssumptionExecuter.PossibleValues enterAssumption = assumptionExecuter.IsSatisfied(); if (enterAssumption == AssumptionExecuter.PossibleValues.OnlyFalse) { return(false); } if (enterAssumption == AssumptionExecuter.PossibleValues.Unknown) { assumptionExecuter.RefineState(); } return(true); }
/// <summary> /// Assume valid condition into output set /// </summary> /// <param name="condition"></param> /// <param name="expressionParts"></param> private void processAssumption(AssumptionCondition condition) { if (condition.Form == ConditionForm.All) { if (condition.Parts.Count() == 1) { var sourceElement = condition.Parts.First().SourceElement; var binary = sourceElement as BinaryEx; assumeBinary(binary); } } }
public override void VisitConditionalEx(ConditionalEx x) { /* Points are created in current ordering * 1. conditionExpr, * 2. trueAssume, * 3. trueExpr, * 4. falseAssume, * 5. falseExpr, */ //1. // starts branching var conditionExpr = CreateRValue(x.CondExpr); //create true branch var trueAssumeCond = new AssumptionCondition(ConditionForm.All, x.CondExpr); var trueAssume = new AssumePoint(trueAssumeCond, new[] { conditionExpr }); //2. AppendToChain(trueAssume); //3. var trueExpr = CreateRValue(x.TrueExpr); //create false branch var falseAssumeCond = new AssumptionCondition(ConditionForm.None, x.CondExpr); var falseAssume = new AssumePoint(falseAssumeCond, new[] { conditionExpr }); //4. AppendToChain(falseAssume); //5. var falseExpr = CreateRValue(x.FalseExpr); //connect condition - true assume will be connected via chaining conditionExpr.AddFlowChild(falseAssume); //create result var expression = new ConditionalExPoint(x, conditionExpr, trueAssume, falseAssume, trueExpr, falseExpr); //false expr is added when processing substitution PreventChainEdge(trueExpr); trueExpr.AddFlowChild(expression); // Both branches must be processed before the expression conditionExpr.CreateWorklistSegment(expression); Result(expression); }
public override void VisitBinaryEx(BinaryEx x) { var lOperand = CreateRValue(x.LeftExpr); ValuePoint rOperand; BinaryExPoint expression; switch (x.PublicOperation) { case Operations.And: case Operations.Or: /* Points are created in current ordering * 1. blockStart, * 2. shortendPath, * 3. nonShortendPath, * 4. rOperand */ var shortableForm = x.PublicOperation == Operations.And ? ConditionForm.None : ConditionForm.All; var nonShortableForm = shortableForm == ConditionForm.All ? ConditionForm.None : ConditionForm.All; var shortableCondition = new AssumptionCondition(shortableForm, x.LeftExpr); //shortened evaluation path var shortendPath = new AssumePoint(shortableCondition, new[] { lOperand }); var nonShortableCondition = new AssumptionCondition(nonShortableForm, x.LeftExpr); //normal evaluation var nonShortendPath = new AssumePoint(nonShortableCondition, new[] { lOperand }); //block borders var blockStart = new EmptyProgramPoint(); //1. AppendToChain(blockStart); //2. AppendToChain(shortendPath); //3. AppendToChain(nonShortendPath); //4. rOperand = CreateRValue(x.RightExpr); expression = new BinaryExPoint(x, lOperand, rOperand); //shortend path is added via chain blockStart.AddFlowChild(nonShortendPath); //set explicit edge PreventChainEdge(shortendPath); shortendPath.AddFlowChild(expression); break; default: rOperand = CreateRValue(x.RightExpr); expression = new BinaryExPoint(x, lOperand, rOperand); break; } Result(expression); }
/// <summary> /// Represents method which is used for confirming assumption condition. /// Assumption can be declined - it means that we can prove, that condition CANNOT be ever satisfied. /// </summary> /// <param name="outSet">Output set where condition will be assumed</param> /// <param name="condition">Assumed condition</param> /// <param name="log">Provide access to values computed during analysis</param> /// <returns>False if you can prove that condition cannot be ever satisfied, true otherwise.</returns> public abstract bool ConfirmAssumption(FlowOutputSet outSet, AssumptionCondition condition, EvaluationLog log);
internal AssumePoint(AssumptionCondition condition, IEnumerable <ValuePoint> expressionParts) { Assumed = false; Condition = condition; }