예제 #1
0
 /// <summary>
 /// Makes the assumption for case like <value>a == b</value>.
 /// </summary>
 /// <param name="left">The left side of the expression.</param>
 /// <param name="right">The right side of the expression.</param>
 /// <param name="memoryContext">The memory context of the code block and it's variables.</param>
 /// <param name="flowOutputSet">The Output set of a program point.</param>
 void AssumeEquals(LangElement left, LangElement right, MemoryContext memoryContext, SnapshotBase flowOutputSet)
 {
     if (right is DirectVarUse && !(left is DirectVarUse))
     {
         AssumeEquals(right, left, memoryContext, flowOutputSet);
     }
     else if (left is DirectVarUse)
     {
         var leftVar = (DirectVarUse)left;
         // this is probably not neceserry {{
         if (right is StringLiteral)
         {
             var rigthValue = (StringLiteral)right;
             memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateString((string)rigthValue.Value));
         }
         else if (right is BoolLiteral)
         {
             var rigthValue = (BoolLiteral)right;
             memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateBool((bool)rigthValue.Value));
         }
         else if (right is DoubleLiteral)
         {
             var rigthValue = (DoubleLiteral)right;
             memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateDouble((double)rigthValue.Value));
         }
         else if (right is IntLiteral)
         {
             var rigthValue = (IntLiteral)right;
             memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateInt((int)rigthValue.Value));
         }
         else if (right is LongIntLiteral)
         {
             var rigthValue = (LongIntLiteral)right;
             memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateLong((long)rigthValue.Value));
         }
         else if (right is NullLiteral)
         {
             //TODO: Is that proper null?
             memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.UndefinedValue);
         }
         //}}
         else
         {
             var snapshotEntry = log.ReadSnapshotEntry(right);
             if (snapshotEntry != null)
             {
                 memoryContext.IntersectionAssign(leftVar.VarName, leftVar, snapshotEntry.ReadMemory(flowOutputSet).PossibleValues);
             }
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Makes the assumption for case like <value>a &lt; b</value>.
        /// </summary>
        /// <param name="left">The left side of the expression.</param>
        /// <param name="right">The right side of the expression.</param>
        /// <param name="equal">if set to <c>true</c> lesser or equals is assumed.</param>
        /// <param name="memoryContext">The memory context of the code block and it's variables.</param>
        /// <param name="flowOutputSet">The Output set of a program point.</param>
        void AssumeLesserThan(LangElement left, LangElement right, bool equal, MemoryContext memoryContext, SnapshotBase flowOutputSet)
        {
            if (right is DirectVarUse && !(left is DirectVarUse))
            {
                AssumeGreaterThan(right, left, equal, memoryContext, flowOutputSet);
            }
            else if (left is DirectVarUse)
            {
                var leftVar = (DirectVarUse)left;
                //this is probably not necessary{
                if (right is StringLiteral)
                {
                    memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.AnyStringValue);
                }
                else if (right is DoubleLiteral)
                {
                    var    rigthValue = (DoubleLiteral)right;
                    double bound      = (double)rigthValue.Value;
                    if (!equal)
                    {
                        bound -= double.Epsilon;
                    }
                    memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateFloatInterval(double.MinValue, bound));
                }
                else if (right is IntLiteral)
                {
                    var rigthValue = (IntLiteral)right;
                    int bound      = (int)rigthValue.Value;
                    if (!equal)
                    {
                        bound--;
                    }
                    memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateIntegerInterval(int.MinValue, bound));
                }
                else if (right is LongIntLiteral)
                {
                    var  rigthValue = (LongIntLiteral)right;
                    long bound      = (long)rigthValue.Value;
                    if (!equal)
                    {
                        bound--;
                    }
                    memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateLongintInterval(long.MinValue, bound));
                }
                //}
                else
                {
                    var snapshotEntry = log.ReadSnapshotEntry(right);
                    if (snapshotEntry != null)
                    {
                        //get upper bound of right and intersect with left
                        int?   maxInt;
                        long?  maxLong;
                        double?maxDouble;
                        ValueHelper.TryGetMaximumValue(snapshotEntry.ReadMemory(flowOutputSet).PossibleValues, out maxInt, out maxLong, out maxDouble);

                        if (maxInt.HasValue)
                        {
                            if (!equal)
                            {
                                maxInt--;
                            }

                            memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateIntegerInterval(int.MinValue, maxInt.Value));
                        }
                        else if (maxLong.HasValue)
                        {
                            if (!equal)
                            {
                                maxLong--;
                            }

                            memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateLongintInterval(long.MinValue, maxLong.Value));
                        }
                        else if (maxDouble.HasValue)
                        {
                            if (!equal)
                            {
                                maxDouble -= double.Epsilon;
                            }

                            memoryContext.IntersectionAssign(leftVar.VarName, leftVar, memoryContext.CreateFloatInterval(double.MinValue, maxDouble.Value));
                        }
                    }
                }
            }
        }