public override Set <BoxedVariable <Variable> > VariablesIn(BoxedExpression exp)
        {
            var retExp = new Set <BoxedExpression>();

            exp.AddFreeVariables(retExp);

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

            foreach (var e in retExp)
            {
                BoxedVariable <Variable> bv;
                if (e.UnderlyingVariable is Variable)
                {
                    bv = new BoxedVariable <Variable>((Variable)e.UnderlyingVariable);
                }
                else if (e.UnderlyingVariable is BoxedVariable <Variable> )
                {
                    bv = (BoxedVariable <Variable>)e.UnderlyingVariable;
                }
                else
                {
                    continue;
                }
                result.Add(bv);
            }

            return(result);
        }
Пример #2
0
                protected void RenameTypes(Dictionary <BoxedVariable <Variable>, FList <BoxedVariable <Variable> > > sourceTargetMap)
                {
                    Contract.Requires(sourceTargetMap != null);

                    Contract.Ensures((this.lastTypeForGetTypeFromHandle != null) == (Contract.OldValue(this.lastTypeForGetTypeFromHandle) != null));

                    if (this.lastTypeForGetTypeFromHandle != null)
                    {
                        var newMap = new Dictionary <Variable, Type>();

                        foreach (var pair in this.lastTypeForGetTypeFromHandle)
                        {
                            var bKey = new BoxedVariable <Variable>(pair.Key);
                            FList <BoxedVariable <Variable> > renamings;
                            if (sourceTargetMap.TryGetValue(bKey, out renamings))
                            {
                                foreach (var newName in renamings.GetEnumerable())
                                {
                                    Variable v;
                                    if (newName.TryUnpackVariable(out v))
                                    {
                                        newMap[v] = pair.Value;
                                    }
                                }
                            }
                        }

                        this.lastTypeForGetTypeFromHandle = newMap;
                    }
                }
Пример #3
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);
                }
Пример #4
0
                public bool CanRefineToArrayLoad(BoxedVariable <Variable> variable, out Pair <BoxedVariable <Variable>, BoxedVariable <Variable> > refined)
                {
                    int id;

                    refined = default(Pair <BoxedVariable <Variable>, BoxedVariable <Variable> >);
                    if (TryGetIdForState(AdditionalStates.ArrayRefinement, out id))
                    {
                        var state = this.PluginAbstractStateAt(id) as ArrayTracking;
                        if (state != null)
                        {
                            ScalarFromArrayTracking value;

                            if (state.TryGetValue(variable, out value) && value.IsNormal())
                            {
                                if (value.Left.IsNormal() && value.Right.IsNormal() &&
                                    value.Left.Count == 1 && value.Right.Count == 1)
                                {
                                    var arr   = value.Left.Values.First();
                                    var index = value.Right.Values.First();

                                    refined = new Pair <BoxedVariable <Variable>, BoxedVariable <Variable> >(arr, index);
                                    return(true);
                                }
                            }
                        }
                    }

                    return(false);
                }
                private List <BoxedExpression> GetForAllVisibleOutsideOfTheMethod(
                    BoxedVariable <Variable> array,
                    ArraySegmentation <FlatAbstractDomainOfBoolsWithRenaming <BoxedVariable <Variable> >, BoxedVariable <Variable>, BoxedExpression> segmentation)
                {
                    Contract.Requires(array != null);
                    Contract.Requires(segmentation != null);

                    var result = new List <BoxedExpression>();

                    var arrayBE = ReadVariableInPreStateForRequires(this.Context.MethodContext.CFG.EntryAfterRequires, array);

                    if (arrayBE != null)
                    {
                        var boundVar   = BoxedExpression.Var("i");
                        var arrayindex = new BoxedExpression.ArrayIndexExpression <Type>(arrayBE, boundVar, this.DecoderForMetaData.System_Object);
                        var factory    = new BoxedExpressionFactory <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Variable>(
                            boundVar, arrayindex,
                            (v => ReadVariableInPreStateForRequires(this.Context.MethodContext.CFG.EntryAfterRequires, v)),
                            this.DecoderForMetaData, null);
                        var formula = segmentation.To(factory);
                        if (formula != null)
                        {
                            result.AddRange(factory.SplitAnd(formula));
                        }
                    }

                    return(result);
                }
                protected ArrayState UpdateArrayAbstractValue(APC pc, BoxedVariable <Variable> arr, NormalizedExpression <BoxedVariable <Variable> > index,
                                                              NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression> ael, ArrayState prevState)
                {
                    Contract.Requires(prevState != null);
                    Contract.Ensures(Contract.Result <ArrayState>() != null);

                    ArraySegmentation <NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression>, BoxedVariable <Variable>, BoxedExpression>
                    prev, updated;

                    if (prevState.Array.TryGetValue(arr, out prev))
                    {
                        if (index != null)
                        {
                            IAbstractDomain prevAel;

                            if (prev.TryGetAbstractValue(index, prevState.Numerical, out prevAel) &&
                                prevAel is NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression> )
                            {
                                ael = ael.Meet(prevAel as NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression>);
                            }

                            if (prev.TrySetAbstractValue(index, ael, prevState.Numerical, out updated))
                            {
                                prevState.Array[arr] = updated;
                            }
                        }
                    }

                    return(prevState);
                }
                public override ArrayState Ldelem(
                    APC pc, Type type, Variable dest, Variable array, Variable index, ArrayState data)
                {
                    Contract.Assume(data != null);

                    var mySubState = Select(data);

                    var boxedArray = new BoxedVariable <Variable>(array);
                    var boxedIndex = new BoxedVariable <Variable>(index);

                    var symbolicConditions = SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> .Unknown;

                    ScalarFromArrayTracking prevInfo;

                    if (mySubState.TryGetValue(new BoxedVariable <Variable>(dest), out prevInfo))
                    {
                        Contract.Assert(prevInfo.Conditions != null);
                        symbolicConditions = symbolicConditions.Meet(prevInfo.Conditions);
                    }

                    var isUnModifiedArrayElement = data.IsUnmodifiedArrayElementFromEntry(boxedArray, ToBoxedExpression(pc, index));

                    var newRelation = new ScalarFromArrayTracking(boxedArray, boxedIndex, isUnModifiedArrayElement, symbolicConditions);

                    mySubState[new BoxedVariable <Variable>(dest)] = newRelation;

                    return(data.UpdatePluginAt(this.Id, mySubState));
                }
 public override void RemoveVariable(BoxedVariable <Variable> var)
 {
     if (this.ContainsKey(var))
     {
         this.RemoveElement(var);
     }
 }
                protected override T To <T>(BoxedVariable <Variable> d, ScalarFromArrayTracking c, IFactory <T> factory)
                {
                    var result = factory.IdentityForAnd;

                    if (c.Left.IsNormal())
                    {
                        T name;
                        if (factory.TryGetBoundVariable(out name))
                        {
                            var first = true;

                            foreach (var x in c.Left.Values)
                            {
                                T arrayLength;
                                if (factory.TryArrayLengthName(factory.Variable(x), out arrayLength))
                                {
                                    var body   = factory.EqualTo(factory.Variable(d), factory.ArrayIndex(factory.Variable(x), name));
                                    var exists = factory.Exists(factory.Constant(0), arrayLength, body);

                                    if (first)
                                    {
                                        result = exists;
                                        first  = false;
                                    }
                                    else
                                    {
                                        result = factory.And(result, exists);
                                    }
                                }
                            }
                        }
                    }

                    return(result);
                }
Пример #10
0
                public bool IsUnmodifiedArrayElementFromEntry(BoxedVariable <Variable> array, BoxedExpression index)
                {
                    int id;

                    if (TryGetIdForState(AdditionalStates.ArrayPurity, out id))
                    {
                        IAbstractDomain element;
                        ArraySegmentation <TwoValuesLattice <BoxedVariable <Variable> >, BoxedVariable <Variable>, BoxedExpression> segmentation;
                        var state = this.PluginAbstractStateAt(id) as ArraySegmentationEnvironment <TwoValuesLattice <BoxedVariable <Variable> >, BoxedVariable <Variable>, BoxedExpression>;
                        if (state != null && state.TryGetValue(array, out segmentation))
                        {
                            // The common case the array is not modified
                            TwoValuesLattice <BoxedVariable <Variable> > value;
                            if (segmentation.Elements.Single(out value) && value.IsBottom)
                            {
                                return(true);
                            }

                            var indexNormalized = index.ToNormalizedExpression <Variable>();
                            // indexNormalized may be null, so we should check it
                            if (indexNormalized != null && segmentation.TryGetAbstractValue(indexNormalized, this.Numerical, out element))
                            {
                                var casted = element as TwoValuesLattice <BoxedVariable <Variable> >;
                                if (casted != null && casted.IsBottom)
                                {
                                    return(true);
                                }
                            }
                        }
                    }

                    return(false);
                }
Пример #11
0
                public bool TryRetrievePreAndPostPartitions(
                    APC pc,
                    BoxedVariable <Variable> array,
                    out Pair <IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression>, IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> > partitions)
                {
                    SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> prePartitions;
                    SimplePartitionAbstractDomain <BoxedVariable <Variable>, BoxedExpression> postPartitions;

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

                                if (postPartitions.TryGetValue(array, out postPartition))
                                {
                                    partitions = new Pair <IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression>, IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> >(prePartition, postPartition);
                                    return(true);
                                }
                            }
                        }
                    }

                    partitions = default(Pair <IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression>, IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> >);
                    return(false);
                }
                public ScalarFromArrayTracking AddCondition(BoxedVariable <Variable> var, BoxedExpression sourceExp)
                {
                    Contract.Requires(sourceExp != null);
                    Contract.Ensures(Contract.Result <ScalarFromArrayTracking>() != null);

                    var conditions = this.conditions.Meet(new SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression>(var, sourceExp));

                    return(new ScalarFromArrayTracking(this.left, this.right, this.isUnmodifiedFromEntry, conditions));
                }
 public ScalarFromArrayTracking(
     BoxedVariable <Variable> left, BoxedVariable <Variable> right,
     FlatAbstractDomain <bool> isUnmodifiedFromEntry,
     SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> conditions)
     : this(new SetOfConstraints <BoxedVariable <Variable> >(left), new SetOfConstraints <BoxedVariable <Variable> >(right),
            isUnmodifiedFromEntry, conditions)
 {
     Contract.Requires(isUnmodifiedFromEntry != null);
     Contract.Requires(conditions != null);
 }
                IEnumerable <BoxedVariable <Variable> > GetEquals(APC pc, BoxedVariable <Variable> arr, ArrayState state)
                {
                    yield return(arr);

                    foreach (var x in new List <BoxedVariable <Variable> >(Select(state).Keys))
                    {
                        if (state.Numerical.CheckIfEqual(ToBoxedExpression(pc, arr), ToBoxedExpression(pc, x)).IsTrue())
                        {
                            yield return(x);
                        }
                    }
                }
                public override ArrayState Ldelem(APC pc, Type type, Variable dest, Variable array, Variable index, ArrayState data)
                {
                    var mySubState = Select(data);
                    var bArray     = new BoxedVariable <Variable>(array);
                    ArraySegmentation <NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression>, BoxedVariable <Variable>, BoxedExpression>
                    existentialSegmentation;

                    var noConstraints = SetOfConstraints <BoxedVariable <Variable> > .Unknown;
                    var newElement    = new NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression>(DisInterval.UnknownInterval, SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> .Unknown,
                                                                                                                      new SetOfConstraints <BoxedVariable <Variable> >(new BoxedVariable <Variable>(dest)),
                                                                                                                      noConstraints, noConstraints, noConstraints, noConstraints);


                    if (mySubState.TryGetValue(bArray, out existentialSegmentation))
                    {
                        if (existentialSegmentation.IsNormal())
                        {
                            var newSegmentation = new ArraySegmentation <NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression>, BoxedVariable <Variable>, BoxedExpression>
                                                      (new NonNullList <SegmentLimit <BoxedVariable <Variable> > >()
                            {
                                existentialSegmentation.Limits.AsIndexable()[0], existentialSegmentation.LastLimit
                            },
                                                      new NonNullList <NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression> >()
                            {
                                newElement
                            },
                                                      existentialSegmentation.Elements.AsIndexable()[0].Bottom, this.ExpressionManager);

                            var meet = existentialSegmentation.Meet(newSegmentation);

                            mySubState.Update(bArray, meet);

                            return(data.UpdatePluginAt(this.Id, mySubState));
                        }
                    }
                    else // materialize
                    {
                        existentialSegmentation = MaterializeArray(this.Context.MethodContext.CFG.Post(pc),
                                                                   mySubState, data.Numerical.CheckIfNonZero, array, newElement, newElement.Bottom);

                        // Segmentation may fail
                        if (existentialSegmentation != null)
                        {
                            mySubState.Update(bArray, existentialSegmentation);

                            return(data.UpdatePluginAt(this.Id, mySubState));
                        }
                    }

                    return(data);
                }
Пример #16
0
                // F: TODO: Lift it to sets (in general we may have several of them)
                public bool IsVariableValueFlowFromArray(BoxedVariable <Variable> variable, out BoxedVariable <Variable> array, out bool unmodifiedFromMethodEntry)
                {
                    // First look into the array refinement substate
                    int id;

                    if (TryGetIdForState(AdditionalStates.ArrayRefinement, out id))
                    {
                        var state = this.PluginAbstractStateAt(id) as ArrayTracking;
                        if (state != null)
                        {
                            ScalarFromArrayTracking value;

                            if (state.TryGetValue(variable, out value) && value.IsNormal())
                            {
                                if (value.Left.IsNormal() && value.Left.Count == 1)
                                {
                                    array = value.Left.Values.First();
                                    unmodifiedFromMethodEntry = value.IsUnmodifiedFromEntry.IsTrue();
                                    return(true);
                                }
                            }
                        }
                    }
                    // Now look into the array existential substate
                    if (TryGetIdForState(AdditionalStates.Existential, out id))
                    {
                        var state = this.PluginAbstractStateAt(id) as ArraySegmentationEnvironment <NonRelationalValueAbstraction <BoxedVariable <Variable>, BoxedExpression>, BoxedVariable <Variable>, BoxedExpression>;
                        if (state != null)
                        {
                            foreach (var segmentation in state.Elements)
                            {
                                if (segmentation.Value.IsNormal())
                                {
                                    foreach (var segment in segmentation.Value.Elements)
                                    {
                                        if (segment.Equalities.Contains(variable))
                                        {
                                            unmodifiedFromMethodEntry = false; // we do not know...
                                            array = segmentation.Key;
                                            return(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    array = default(BoxedVariable <Variable>);
                    unmodifiedFromMethodEntry = default(bool);
                    return(false);
                }
                public override ArrayState Stelem(APC pc, Type type, Variable array, Variable index, Variable value, ArrayState data)
                {
                    var mySubState = Select(data);
                    var bArray     = new BoxedVariable <Variable>(array);

                    if (mySubState.ContainsKey(bArray))
                    {
                        mySubState.RemoveElement(bArray);

                        return(data.UpdatePluginAt(this.Id, mySubState));
                    }

                    return(data);
                }
                private bool TryParameterFor(BoxedVariable <Variable> var, out Parameter p, out int pos)
                {
                    Contract.Requires(var != null);

                    Variable v;

                    if (var.TryUnpackVariable(out v) && TryParameterFor(v, out p, out pos))
                    {
                        return(true);
                    }

                    pos = -1;
                    p   = default(Parameter);
                    return(false);
                }
                    // only knows how to answer questions in the form a == b
                    public ProofOutcome IsTrue(APC pc, BoxedExpression condition)
                    {
                        BinaryOperator  bop;
                        BoxedExpression left, right;
                        ArrayState      preState;

                        if (condition.IsBinaryExpression(out bop, out left, out right) &&
                            (bop == BinaryOperator.Ceq || bop == BinaryOperator.Cne_Un) &&
                            this.fixpoint.PreState(pc, out preState))
                        {
                            var mySubState = analysis.Select(preState);

                            Variable s1, s2;

                            if (left.TryGetFrameworkVariable(out s1) && right.TryGetFrameworkVariable(out s2))
                            {
                                var s1Boxed = new BoxedVariable <Variable>(s1);
                                var s2Boxed = new BoxedVariable <Variable>(s2);

                                ScalarFromArrayTracking value1, value2;

                                if (mySubState.TryGetValue(s1Boxed, out value1) && value1.IsNormal() &&
                                    mySubState.TryGetValue(s2Boxed, out value2) && value2.IsNormal())
                                {
                                    BoxedVariable <Variable> arr1, arr2;
                                    BoxedVariable <Variable> index1, index2;

                                    if (value1.Left.IsSingleton(out arr1) && value2.Left.IsSingleton(out arr2) && arr1.Equals(arr2))
                                    {
                                        if (value1.Right.IsSingleton(out index1) && value2.Right.IsSingleton(out index2) && index1.Equals(index2))
                                        {
                                            if (bop == BinaryOperator.Ceq)
                                            {
                                                return(ProofOutcome.True);
                                            }
                                            else
                                            {
                                                Contract.Assert(bop == BinaryOperator.Cne_Un);
                                                return(ProofOutcome.False);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        return(ProofOutcome.Top);
                    }
                protected ArraySegmentation <Elements, BoxedVariable <Variable>, BoxedExpression> MaterializeArray <Elements>(
                    APC postPC, ArraySegmentationEnvironment <Elements, BoxedVariable <Variable>, BoxedExpression> preState,
                    Func <BoxedExpression, FlatAbstractDomain <bool> > CheckIfNonZero, Variable arrayValue, Elements initialValue, Elements bottom)
                    where Elements : class, IAbstractDomainForArraySegmentationAbstraction <Elements, BoxedVariable <Variable> >
                {
                    Contract.Requires(preState != null);
                    Contract.Requires(initialValue != null);

                    var boxSym = new BoxedVariable <Variable>(arrayValue);

                    ArraySegmentation <Elements, BoxedVariable <Variable>, BoxedExpression> arraySegment;

                    if (preState.TryGetValue(boxSym, out arraySegment))
                    {
                        return(arraySegment); // already materialized
                    }

                    Variable array_Length;

                    if (this.Context.ValueContext.TryGetArrayLength(postPC, arrayValue, out array_Length))
                    {
                        var isNonEmpty = CheckIfNonZero(this.ToBoxedExpression(postPC, array_Length)).IsTrue();

                        var limits = new NonNullList <SegmentLimit <BoxedVariable <Variable> > >()
                        {
                            new SegmentLimit <BoxedVariable <Variable> >(NormalizedExpression <BoxedVariable <Variable> > .For(0), false),                                               // { 0 }
                            new SegmentLimit <BoxedVariable <Variable> >(NormalizedExpression <BoxedVariable <Variable> > .For(new BoxedVariable <Variable>(array_Length)), !isNonEmpty) // { symb.Length }
                        };

                        var elements = new NonNullList <Elements>()
                        {
                            initialValue
                        };

                        var newSegment = new ArraySegmentation <Elements, BoxedVariable <Variable>, BoxedExpression>(
                            limits, elements,
                            bottom,
                            this.ExpressionManager);

                        preState.AddElement(new BoxedVariable <Variable>(arrayValue), newSegment);

                        return(newSegment);
                    }

                    return(null);
                }
Пример #21
0
        public bool Equals(BoxedVariable <Variable> other)
        {
            Contract.Assume(other != null);

            if (this.innerVar != null)
            {
                if (other.innerVar != null)
                {
                    return(this.innerVar.Equals(other.innerVar));
                }
            }
            else if (other.innerVar == null)
            {
                return(this.var.Equals(other.var));
            }

            return(false);
        }
Пример #22
0
                private SimpleArrayPropertiesAbstractDomain <BoxedVariable <Variable>, BoxedExpression> AdaptPartition(
                    BoxedVariable <Variable> array,
                    SimpleArrayPropertiesAbstractDomain <BoxedVariable <Variable>, BoxedExpression> dataContents,
                    IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> fromPartition,
                    IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> toPartition)
                {
                    // Assumption: fromPartition is not top
                    if (fromPartition.IsTop)
                    {
                        throw new AbstractInterpretationException();
                    }

                    var transformMap = fromPartition.TransformationMapFor(toPartition);

                    dataContents.TransformArray(array, transformMap);

                    return(dataContents);
                }
                public override void RemoveVariable(BoxedVariable <Variable> var)
                {
                    if (this.IsNormal())
                    {
                        if (this.ContainsKey(var))
                        {
                            this.RemoveElement(var);
                        }
                        else
                        {
                            var toUpdate = new List <Pair <BoxedVariable <Variable>, SetOfConstraints <BoxedExpression> > >();

                            foreach (var pair in this.Elements)
                            {
                                if (pair.Value.IsNormal())
                                {
                                    var toRemove = new List <BoxedExpression>();

                                    foreach (var el in pair.Value.Values)
                                    {
                                        if (el.Variables <Variable>().ConvertAll(v => new BoxedVariable <Variable>(v)).Contains(var))
                                        {
                                            toRemove.Add(el);
                                        }
                                    }

                                    if (toRemove.Count > 0)
                                    {
                                        toUpdate.Add(pair.Key, new SetOfConstraints <BoxedExpression>(pair.Value.Values.Except(toRemove)));
                                    }
                                }
                            }

                            if (toUpdate.Count > 0)
                            {
                                foreach (var pair in toUpdate)
                                {
                                    this[pair.One] = pair.Two;
                                }
                            }
                        }
                    }
                }
Пример #24
0
                public override ArrayState Assume(APC pc, string tag, Variable source, object provenance, ArrayState data)
                {
                    var md   = this.MethodDriver;
                    var cond = BoxedExpression.Convert(md.Context.ExpressionContext.Refine(pc, source), md.ExpressionDecoder).Simplify(md.MetaDataDecoder);

                    Type     type;
                    Variable var;

                    if (cond != null)
                    {
                        // normalize assume(false) !(...)
                        if (tag == "false" && cond.IsUnary && cond.UnaryOp == UnaryOperator.Not)
                        {
                            cond = cond.UnaryArgument;
                        }

                        if (cond.IsAssumeIsAType(out var, out type))
                        {
                            return(data.UpdatePluginAt(this.Id, Select(data).Update(var, type)));
                        }

                        Variable left, right;
                        if (cond.IsBinary && cond.BinaryOp == BinaryOperator.Cobjeq & cond.BinaryLeft.TryGetFrameworkVariable(out left) && cond.BinaryRight.TryGetFrameworkVariable(out right))
                        {
                            var  runtimeTypes = Select(data);
                            var  boxedLeft    = new BoxedVariable <Variable>(left);
                            var  boxedRight   = new BoxedVariable <Variable>(right);
                            Type t;
                            if (runtimeTypes.TryGetValue(left, out t))
                            {
                                runtimeTypes[boxedRight] = t;
                            }
                            if (runtimeTypes.TryGetValue(right, out t))
                            {
                                runtimeTypes[boxedLeft] = t;
                            }

                            return(data.UpdatePluginAt(this.Id, runtimeTypes));
                        }
                    }

                    return(base.Assume(pc, tag, source, provenance, data));
                }
Пример #25
0
                private SimpleArrayPropertiesAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Normalize(
                    BoxedVariable <Variable> array,
                    SimpleArrayPropertiesAbstractDomain <BoxedVariable <Variable>,
                                                         BoxedExpression> dataContents,
                    INumericalAbstractDomain <BoxedVariable <Variable>, BoxedExpression> dataIndexes,
                    IPartitionAbstraction <BoxedVariable <Variable>, BoxedExpression> partition)
                {
                    if (dataIndexes.IsBottom)
                    {
                        // TODO
                    }

                    var knowledge = dataIndexes.To <BoxedExpression>(new BoxedExpressionFactory <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly>(this.DecoderForMetaData));

                    var emptyDimensions = partition.EmptyDimensionsInContext(knowledge);

                    dataContents.SimplifyArray(array, emptyDimensions);

                    return(dataContents);
                }
                public override ArrayState Stelem(APC pc, Type type, Variable array, Variable index, Variable value, ArrayState data)
                {
                    Contract.Assume(data != null);

                    var mySubState = Select(data);

                    var boxedArray = new BoxedVariable <Variable>(array);
                    var boxedIndex = new BoxedVariable <Variable>(index);


                    if (mySubState.IsNormal())
                    {
                        var toRemove = new List <BoxedVariable <Variable> >();
                        foreach (var pair in mySubState.Elements)
                        {
                            var el = pair.Value;
                            if (el.IsNormal() && el.Left.IsNormal() && el.Left.Contains(boxedArray) && el.Right.IsNormal() && el.Right.Contains(boxedIndex))
                            {
                                toRemove.Add(pair.Key);
                            }
                        }

                        foreach (var k in toRemove)
                        {
                            mySubState.RemoveElement(k);
                        }
                    }

                    var isUnModifiedArrayElement = data.IsUnmodifiedArrayElementFromEntry(boxedArray, ToBoxedExpression(pc, index));

                    var newRelation = new ScalarFromArrayTracking(boxedArray, boxedIndex, isUnModifiedArrayElement, SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> .Unknown);

                    mySubState[new BoxedVariable <Variable>(value)] = newRelation;

                    return(data.UpdatePluginAt(this.Id, mySubState));
                }
                    protected override ProofOutcome VisitIsPureArray(BoxedVariable <Variable> array)
                    {
                        ArraySegmentation <TwoValuesLattice <BoxedVariable <Variable> >, BoxedVariable <Variable>, BoxedExpression> arrayAbstraction;

                        if (this.state.TryGetValue(array, out arrayAbstraction))
                        {
                            if (arrayAbstraction.IsEmptyArray)
                            {
                                return(ProofOutcome.Top);
                            }

                            foreach (var el in arrayAbstraction.Elements)
                            {
                                if (!el.IsBottom)
                                {
                                    return(ProofOutcome.Top);
                                }
                            }

                            return(ProofOutcome.True);
                        }

                        return(ProofOutcome.Top);
                    }
Пример #28
0
 void IPureExpressionAssignments <BoxedVariable <Variable>, BoxedExpression> .RenameVariable(BoxedVariable <Variable> OldName, BoxedVariable <Variable> NewName)
 {
     throw new NotImplementedException();
 }
Пример #29
0
 void IPureExpressionAssignments <BoxedVariable <Variable>, BoxedExpression> .RemoveVariable(BoxedVariable <Variable> var)
 {
     throw new NotImplementedException();
 }
Пример #30
0
                public SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> SymbolicConditions(BoxedVariable <Variable> variable)
                {
                    Contract.Requires(variable != null);
                    Contract.Ensures(Contract.Result <SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> >() != null);

                    int id;

                    if (TryGetIdForState(AdditionalStates.ArrayRefinement, out id))
                    {
                        var state = this.PluginAbstractStateAt(id) as ArrayTracking;
                        ScalarFromArrayTracking arrayTracking;
                        if (state != null && state.TryGetValue(variable, out arrayTracking))
                        {
                            Contract.Assume(arrayTracking != null);

                            return(arrayTracking.Conditions);
                        }
                    }

                    return(SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> .Unknown);
                }