Пример #1
0
                public override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Binary(APC pc, BinaryOperator op, Variable dest, Variable s1, Variable s2, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    var indexes  = this.indexesAnalysis.Binary(pc, op, dest, s1, s2, data.Left);
                    var contents = data.Right;

                    if (OperatorExtensions.IsComparisonBinaryOperator(op))
                    {
                        // TODO: if s1 or s2 includes an array term, gaurd must be take into account
                        return(new SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression>(indexes, contents));
                    }
                    else if (OperatorExtensions.IsBooleanBinaryOperator(op))
                    {
                        // TODO: see above
                        return(new SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression>(indexes, contents));
                    }
                    else
                    {
                        var leftAsExp  = ToBoxedExpressionWithConstantRefinement(pc, s1);
                        var rightAsExp = ToBoxedExpressionWithConstantRefinement(pc, s2);

                        // adapt
                        BoxedExpression rightOfAssignment;
                        if (TryRepackAssignment(op, leftAsExp, rightAsExp, out rightOfAssignment))
                        {
                            SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> prePartitions;
                            SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> postPartitions;

                            if (this.partitions.TryPartitionAt(pc, out prePartitions))
                            {
                                var arraysToRefine = prePartitions.arraysWithPartitionDefinedOnASubsetExpressionOf(rightOfAssignment);

                                // NOTE: this does not means that each array in arraysToRefine are in the current state, BUT they should be

                                foreach (var arrayAsExp in arraysToRefine)
                                {
                                    if (this.partitions.TryPartitionAt(this.Context.Post(pc), out postPartitions))
                                    {
                                        IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> prePartition;
                                        IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> postPartition;
                                        if (prePartitions.TryGetValue(arrayAsExp, out prePartition))
                                        {
                                            if (postPartitions.TryGetValue(arrayAsExp, out postPartition))
                                            {
                                                contents = AdaptPartition(arrayAsExp, contents, prePartition, postPartition);
                                            }
                                        }
                                        //refinedDomain = HandleIndexAssignment("", pc, arrayAsExp, destAsExp, rightOfAssignment, assignmentKnowledge, refinedDomain);
                                    }
                                }
                            }
                        }
                    }

                    return(new SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression>(indexes, contents));
                }
Пример #2
0
 public virtual void ReadFrom(XElement xE)
 {
     Operator      = null;
     OperationType = null;
     foreach (var xItem in xE.Elements())
     {
         var localName = xItem.Name.LocalName;
         if (localName == "operator")
         {
             Operator = OperatorExtensions.Parse(xItem.Value);
         }
         else if (localName == "Operation.Type")
         {
             OperationType = xItem.Value;
         }
     }
 }
Пример #3
0
                public override SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Binary(APC pc, BinaryOperator op, Variable dest, Variable s1, Variable s2, SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    Log("Binary:{0}", op);
                    if (OperatorExtensions.IsComparisonBinaryOperator(op))
                    {
                        // TODO: if s1 or s2 includes an array term, partitioning must be done.
                        return(data);
                    }
                    else if (OperatorExtensions.IsBooleanBinaryOperator(op))
                    {
                        // TODO: see above
                        return(data);
                    }
                    else
                    {
                        var destAsExp  = ToBoxedExpression(pc, dest);
                        var leftAsExp  = ToBoxedExpressionWithConstantRefinement(pc, s1);
                        var rightAsExp = ToBoxedExpressionWithConstantRefinement(pc, s2);

                        ALog.BeginTransferFunction(StringClosure.For("Assign"),
                                                   StringClosure.For("{0} := {1}({2}, {3})",
                                                                     ExpressionPrinter.ToStringClosure(destAsExp, this.Decoder), StringClosure.For(op),
                                                                     ExpressionPrinter.ToStringClosure(leftAsExp, this.Decoder), ExpressionPrinter.ToStringClosure(rightAsExp, this.Decoder)),
                                                   PrettyPrintPC(pc), StringClosure.For(data));

                        // Hypothesis : if it is a reminder or division operation, we assume that the dividend is not zero
                        var             refinedDomain = data;
                        BoxedExpression rightOfAssignment;

                        Log("REPACK:{1} {0} {2}", op, s1, s2);

                        if (TryRepackAssignment(op, leftAsExp, rightAsExp, out rightOfAssignment))
                        {
                            var arraysToRefine = data.arraysWithPartitionDefinedOnASubsetExpressionOf(rightOfAssignment);

                            if (!arraysToRefine.IsEmpty)
                            {
                                var assignmentKnowledge         = this.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.Equal, destAsExp, rightOfAssignment);
                                var assignmentStrippedKnowledge = this.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.Equal, destAsExp, RecursiveStripped(rightOfAssignment));
                                assignmentKnowledge = this.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.And, assignmentKnowledge, assignmentStrippedKnowledge);

                                //Log("KNOWLEDGEonREPACK:{0}", rightOfAssignment);

                                foreach (var array in arraysToRefine)
                                {
                                    refinedDomain = HandleIndexAssignment("", pc,
                                                                          array,
                                                                          ToBoxedVariable(dest),
                                                                          rightOfAssignment,
                                                                          assignmentKnowledge, refinedDomain);
                                }
                            }
                        }
                        //else
                        //{
                        //  throw new AbstractInterpretationException(); //TODO : leave the else.
                        //}

                        ALog.EndTransferFunction(StringClosure.For(refinedDomain));

                        return(refinedDomain);
                    }
                }