/// <summary> /// Creates points block from given condition /// Points block will have single outgoing block as outcomming edge /// </summary> /// <param name="condition">Condition which points block is created</param> /// <param name="outgoingBlock">Block used as outcomming edge</param> /// <param name="expressionValues">Expression parts of assumed condition</param> /// <returns>Created points block</returns> internal PointsBlock CreateAssumeBlock(AssumptionCondition condition, BasicBlock outgoingBlock, params ValuePoint[] expressionValues) { var point = new AssumePoint(condition, expressionValues); reportCreation(point); var createdBlock = PointsBlock.ForPoint(point, new[] { outgoingBlock }); _createdBlocks.Add(createdBlock); return(createdBlock); }
internal bool ConfirmAssumption(FlowController flow, AssumptionCondition condition) { return(FlowResolver.ConfirmAssumption(flow.OutSet, condition, flow.Log)); }
/// <summary> /// Connect outgoing condition edges from parentBlock with belonging children point blocks via assume blocks /// </summary> /// <param name="parentBlock">Parent point block which children point blocks will be connected</param> /// <param name="pendingBlocks">Point blocks which children hasn't been processed yet</param> private void connectConditionEdges(PointsBlock parentBlock, Queue <PointsBlock> pendingBlocks) { //collected expression values - because of sharing with default branch var expressionValues = new List <ValuePoint>(); //collected expression parts - because of default assumption condition creation var expressionParts = new List <Expression>(); //collected expression blocks - because of connecting default assumption var expressionBlocks = new List <PointsBlock>(); //process all outgoing conditional edges // For each conditional edge, create block and append it as a child of parrent block // TODO: in current CFG, there should be always at most one conditional edge foreach (var edge in parentBlock.ConditionalEdges) { Expression expression; if (edge.EdgeType == BasicBlockEdgeTypes.CONDITIONAL) { expression = edge.Condition; } else if (edge.EdgeType == BasicBlockEdgeTypes.FOREACH) { //now is foreach handled without condition processing (edge is added as non conditional) connectConditionLessEdge(parentBlock, edge.To, pendingBlocks); continue; } else { throw new NotSupportedException("Not supported CFG edge of type: " + edge.GetType()); } var conditionExpressionBlock = _context.CreateFromExpression(expression); var expressionValue = conditionExpressionBlock.LastPoint as ValuePoint; //collect info for default branch expressionValues.Add(expressionValue); expressionParts.Add(expression); expressionBlocks.Add(conditionExpressionBlock); var condition = new AssumptionCondition(ConditionForm.All, expression); parentBlock.AddChild(conditionExpressionBlock); //connect edge.To through assume block var assumeBlock = _context.CreateAssumeBlock(condition, edge.To, expressionValue); conditionExpressionBlock.AddChild(assumeBlock); //assume block needs processing of its children pendingBlocks.Enqueue(assumeBlock); } //if there is default branch if (parentBlock.Default != null) { if (expressionValues.Count == 0) { //there is default branch without any condition - connect without assume block // connect default branch to parent var defaultBlock = getChildBlock(parentBlock.Default, pendingBlocks); //default block needs processing of its children parentBlock.AddChild(defaultBlock); } else { //there has to be assumption condition on default branch // connect default branch to conditional blocks var values = expressionValues.ToArray(); var condition = new AssumptionCondition(ConditionForm.None, expressionParts.ToArray()); var defaultAssumeBlock = _context.CreateAssumeBlock(condition, parentBlock.Default, values); //default Assume has to be added as child of all expression blocks foreach (var conditionExpression in expressionBlocks) { conditionExpression.AddChild(defaultAssumeBlock); } pendingBlocks.Enqueue(defaultAssumeBlock); } } }