Пример #1
0
        /// <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);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Connect outgoing condition less edge from parentBlock with given child
        /// </summary>
        /// <param name="parentBlock">Parent point block which child block will be connected</param>
        /// <param name="child">Block connected as child of parent block</param>
        /// <param name="pendingBlocks">Point blocks which children hasn't been processed yet</param>
        private void connectConditionLessEdge(PointsBlock parentBlock, BasicBlock child, Queue <PointsBlock> pendingBlocks)
        {
            var childBlock = getChildBlock(child, pendingBlocks);

            parentBlock.AddChild(childBlock);
        }