Ejemplo n.º 1
0
                public bool LookupState(IMethodResult <Variable> mr, APC pc, out SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> astate)
                {
                    astate = null;
                    ContainerAnalysis an = mr as ContainerAnalysis;

                    if (an == null)
                    {
                        return(false);
                    }

                    return(an.PreStateLookup(pc, out astate));
                }
Ejemplo n.º 2
0
                public bool AssignInParallel(IMethodResult <Variable> mr, ref SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> astate, Dictionary <BoxedVariable <Variable>, FList <BoxedVariable <Variable> > > mapping, Converter <BoxedVariable <Variable>, BoxedExpression> convert)
                {
                    ContainerAnalysis an = mr as ContainerAnalysis;

                    if (an == null)
                    {
                        return(false);
                    }

                    astate.AssignInParallel(mapping, convert);
                    return(true);
                }
Ejemplo n.º 3
0
                public override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Ldelema(APC pc, Type type, bool @readonly, Variable dest, Variable array, Variable index, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    var indexes  = this.indexesAnalysis.Ldelema(pc, type, @readonly, dest, array, index, data.Left);
                    var contents = data.Right;

                    return(new SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression>(indexes, contents));
                }
Ejemplo n.º 4
0
                public override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Newarray <ArgList>(APC pc, Type type, Variable dest, ArgList lengths, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    var indexes  = this.indexesAnalysis.Newarray <ArgList>(pc, type, dest, lengths, data.Left);
                    var contents = data.Right;

                    if (lengths.Count > 1)
                    {
                        return(new SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression>(indexes, contents));
                    }
                    else
                    {
                        contents = HandleAllocations(pc, type, dest, lengths[0], contents);
                    }

                    return(new SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression>(indexes, contents));
                }
Ejemplo n.º 5
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));
                }
Ejemplo n.º 6
0
                public override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Castclass(APC pc, Type type, Variable dest, Variable obj, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    if (isOneDimensionalArray(pc, dest))
                    {
                        return(GenericArrayHandling(pc, dest, data));
                    }

                    return(data);
                }
Ejemplo n.º 7
0
                public override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Ldfld(APC pc, Field field, bool @volatile, Variable dest, Variable obj, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    if (isOneDimensionalArray(pc, dest))
                    {
                        return(GenericArrayHandling(pc, dest, data));
                    }

                    return(data);
                }
Ejemplo n.º 8
0
                public override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Ldarg(APC pc, Parameter argument, bool isOld, Variable dest, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    // TODO: what is isOld for ?
                    if (isOneDimensionalArray(pc, dest))
                    {
                        return(GenericArrayHandling(pc, dest, data));
                    }

                    return(data);
                }
Ejemplo n.º 9
0
                /// <summary>
                ///
                /// </summary>
                private SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> GenericArrayHandling(APC pc, Variable array, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    Variable arrayLengthVar;

                    //var type = this.Context.GetType(pc, dest);
                    if (this.Context.TryGetArrayLength(this.Context.Post(pc), array, out arrayLengthVar))
                    {
                        var arrayB = new BoxedVariable <Variable>(array);

                        // if a symbolic value is assigned twice, thanks to symbolic values semantics, its equivalent to nop.
                        // So we keep the arraysProperties such as they are.
                        if (!data.Right.ContainsKey(arrayB))
                        {
                            var arrayType = this.Context.GetType(this.Context.Post(pc), array);
                            if (arrayType.IsNormal)
                            {
                                var type     = this.DecoderForMetaData.ElementType(arrayType.Value);
                                var contents = data.Right;
                                contents = HandleAllocations(pc, type, array, arrayLengthVar, contents);
                                return(new SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression>(data.Left, contents, this.Decoder, this.Encoder));
                            }
                            else
                            {
                                throw new AbstractInterpretationException();
                            }
                        }

                        return(data);
                    }

                    Debug.Assert(false, "ArrayLength of an array must be known");

                    return(data);
                }
Ejemplo n.º 10
0
                public override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Assume(APC pc, string tag, Variable source, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data)
                {
                    var result   = base.Assume(pc, tag, source, data);
                    var contents = result.Right;

                    // TODO : before calling normalize see if invovled variables are into the partition
                    //var refinedExp = ToBoxedExpression(pc, source);

                    SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> postPartitions;

                    if (this.partitions.TryPartitionAt(this.Context.Post(pc), out postPartitions))
                    {
                        IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> postPartition;

                        var arrays = new List <BoxedVariable <Variable> >(contents.Keys);

                        foreach (var array in arrays)
                        {
                            if (postPartitions.TryGetValue(array, out postPartition))
                            {
                                contents = Normalize(array, contents, result.Left, postPartition);
                            }
                        }
                    }

                    return(result);
                }
Ejemplo n.º 11
0
                public override void HelperForAssignInParallel(SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> state, Pair <APC, APC> edge, Dictionary <BoxedVariable <Variable>, FList <BoxedVariable <Variable> > > refinedMap, Converter <BoxedVariable <Variable>, BoxedExpression> convert)
                {
                    //state.Left.AssignInParallel(refinedMap);

                    // Warning : multiple assigned vriables can have different post partitions, because they are the result
                    // of the whole analysis, and some merge could have happenned for only one of the multiple assigned.
                    // tht is why you assign in pralle before adapt arrayProperties

                    var originalArrays = new List <BoxedVariable <Variable> >(state.Right.Keys);

                    base.HelperForAssignInParallel(state, edge, refinedMap, convert);

                    SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> prePartitions;

                    if (this.partitions.TryPartitionAt(edge.One, out prePartitions))
                    {
                        var contents = state.Right;

                        foreach (var array in originalArrays)
                        {
                            // if the array is kept
                            if (refinedMap.ContainsKey(array))
                            {
                                IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> prePartition;
                                if (prePartitions.TryGetValue(array, out prePartition))
                                {
                                    var prePartitionRebinded = prePartition.PartialAssignInParallel(refinedMap, convert);

                                    SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> postPartitions;

                                    if (this.partitions.TryPartitionAt(edge.Two, out postPartitions))
                                    {
                                        IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> postPartition;
                                        //arrayRebinded = refinedMap[array].Head;
                                        foreach (var arrayRebinded in refinedMap[array].GetEnumerable())
                                        {
                                            if (postPartitions.TryGetValue(arrayRebinded, out postPartition))
                                            {
                                                var transformMap = prePartitionRebinded.TransformationMapFor(postPartition);

                                                contents.TransformArray(arrayRebinded, transformMap);
                                                contents = Normalize(arrayRebinded, contents, state.Left, postPartition);
                                            }
                                            else
                                            {
                                                // no partition in postState ...
                                                // TODO : make the arrayproperties attached to the array disappear.
                                                contents.RemoveElement(arrayRebinded);
                                                //throw new AbstractInterpretationException();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        throw new AbstractInterpretationException();
                                    }
                                }
                            }
                        }
                        //state = new SimpleArrayAbstractDomain<BoxedVariable<Variable>, BoxedExpression>(
                    }
                    else
                    {
                        throw new AbstractInterpretationException();
                    }

                    //base.HelperForAssignInParallel(state, edge, refinedMap);
                    //state.Right.AssignInParallel(refinedMap);
                }
Ejemplo n.º 12
0
                protected override SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> HelperForJoin(SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> newState, SimpleArrayAbstractDomain <BoxedVariable <Variable>, BoxedExpression> prevState, Pair <APC, APC> edge)
                {
                    /// - that an array can be null, and in his case not appearing into the environment

                    var keep = new Set <BoxedVariable <Variable> >();

                    foreach (var array in prevState.Right.Variables)
                    {
                        SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> postPartitions;

                        if (this.partitions.TryPartitionAt(edge.Two, out postPartitions))
                        {
                            IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> postPartition;

                            if (postPartitions.TryGetValue(array, out postPartition))
                            {
                                keep.Add(array);
                            }
                        }
                        else
                        {
                            throw new AbstractInterpretationException();
                        }
                    }

                    var result = newState.Join(prevState, keep);

                    //return base.HelperForJoin(newState, prevState, edge);
                    return(result);
                }