Exemple #1
0
 public override Term VisitI8(TVoid parameter, Term term, long value)
 {
     if (this.lastAccessedField != null && this.lastAccessedField.Type.ToString() == "System.Int64")
     {
         FieldValueHolder fvh = new FieldValueHolder(FieldValueType.LONG);
         fvh.longValue = value;
         this.FieldValues[lastAccessedField] = fvh;
     }
     return(base.VisitI8(parameter, term, value));
 }
Exemple #2
0
 public override Term VisitI2(TVoid parameter, Term term, short value)
 {
     if (this.lastAccessedField != null && this.lastAccessedField.Type.ToString() == "System.Int16")
     {
         FieldValueHolder fvh = new FieldValueHolder(FieldValueType.SHORT);
         fvh.shortValue = value;
         this.FieldValues[lastAccessedField] = fvh;
     }
     return(base.VisitI2(parameter, term, value));
 }
Exemple #3
0
 public override Term VisitI4(TVoid parameter, Term term, int value)
 {
     if (this.lastAccessedField != null && this.lastAccessedField.Type.ToString() == "System.Int32")
     {
         FieldValueHolder fvh = new FieldValueHolder(FieldValueType.INTEGER);
         fvh.intValue = value;
         this.FieldValues[lastAccessedField] = fvh;
     }
     return(base.VisitI4(parameter, term, value));
 }
        /// <summary>
        /// Computes fitness values. TODO: handles only integer and boolean. Needs to be extended for other types
        /// </summary>
        /// <param name="field"></param>
        /// <param name="actual"></param>
        /// <param name="expected"></param>
        /// <param name="host"></param>
        /// <param name="fmt"></param>
        /// <param name="fitnessval"></param>
        public static void ComputeFitnessValue(Field field, FieldValueHolder actual, FieldValueHolder expected, IPexComponent host,
            out FieldModificationType fmt, out int fitnessval)
        {
            fitnessval = Int32.MaxValue;
            fmt = FieldModificationType.UNKNOWN;
            try
            {
                string fieldType = field.Type.ToString();
                if (fieldType == "System.Int32")
                {
                    fitnessval = Math.Abs(actual.intValue - expected.intValue);
                    if (actual.intValue < expected.intValue)
                    {
                        fmt = FieldModificationType.INCREMENT;
                    }
                    else if (actual.intValue > expected.intValue)
                    {
                        fmt = FieldModificationType.DECREMENT;
                    }
                    return;
                }

                if (fieldType == "System.Boolean")
                {
                    if (expected.boolValue)
                        fmt = FieldModificationType.TRUE_SET;
                    else
                        fmt = FieldModificationType.FALSE_SET;
                    return;
                }

                if (fieldType == "System.Int16")
                {
                    fitnessval = Math.Abs(actual.shortValue - expected.shortValue);
                    if (actual.shortValue < expected.shortValue)
                    {
                        fmt = FieldModificationType.INCREMENT;
                    }
                    else if (actual.shortValue > expected.shortValue)
                    {
                        fmt = FieldModificationType.DECREMENT;
                    }
                    return;
                }

                if (fieldType == "System.Int64")
                {
                    fitnessval = (int)Math.Abs(actual.longValue - expected.longValue);
                    if (actual.longValue < expected.longValue)
                    {
                        fmt = FieldModificationType.INCREMENT;
                    }
                    else if (actual.longValue > expected.longValue)
                    {
                        fmt = FieldModificationType.DECREMENT;
                    }
                    return;
                }

                if (field.Type.IsReferenceType)
                {
                    if (expected.objValue == null)
                        fmt = FieldModificationType.NULL_SET;
                    else
                        fmt = FieldModificationType.NON_NULL_SET;
                }

                host.Log.LogWarning(WikiTopics.MissingWikiTopic, "FitnexCompute", "Handles only integer and boolean types.");
            }
            catch (OverflowException ofe)
            {
                host.Log.LogCriticalFromException(ofe, WikiTopics.MissingWikiTopic, "FitnessMeasure", "Overflow error occurred while computing fitness values");
            }
        }
Exemple #5
0
        /// <summary>
        /// Stores the expected field value. Currently implemented for integers for time being
        /// </summary>
        /// <param name="termManager"></param>
        /// <param name="field"></param>
        /// <param name="fieldValue"></param>
        /// <param name="expectedFieldValues"></param>
        /// <param name="host"></param>
        /// <param name="condition"></param>
        /// <param name="binOp"></param>
        private static void StoreFieldValue(TermManager termManager, Field field, Term fieldValue,
                                            SafeDictionary <Field, FieldValueHolder> expectedFieldValues, SafeDictionary <Field, FieldValueHolder> actualFieldValues,
                                            SafeList <Field> allFieldsInCondition, IPexComponent host, Term condition, BinaryOperator binOp)
        {
            TypeEx fieldType = field.Type;

            if (fieldType == SystemTypes.Int32)
            {
                int value;
                if (termManager.TryGetI4Constant(fieldValue, out value))
                {
                    FieldValueHolder fvh = new FieldValueHolder(FieldValueType.INTEGER);
                    fvh.intValue = value;
                    expectedFieldValues.Add(field, fvh);
                }
                return;
            }

            //Gathering the expected value for boolean field
            Term unnegatedCondition;
            bool bNegated = false;

            if (termManager.TryGetInnerLogicallyNegatedValue(condition, out unnegatedCondition))
            {
                bNegated = true;
            }
            else
            {
                unnegatedCondition = condition;
            }

            if (fieldType == SystemTypes.Bool)
            {
                if (binOp == BinaryOperator.Ceq)
                {
                    FieldValueHolder fvh = new FieldValueHolder(FieldValueType.BOOLEAN);
                    fvh.boolValue = bNegated;
                    expectedFieldValues.Add(field, fvh);

                    //For boolean, actual value does not matter. However, without
                    //proper entry in the acutal field, it would not considered for further processing
                    if (allFieldsInCondition.Contains(field) && !actualFieldValues.Keys.Contains(field))
                    {
                        FieldValueHolder fvhtemp = new FieldValueHolder(FieldValueType.BOOLEAN);
                        fvhtemp.boolValue = false;
                        actualFieldValues.Add(field, fvhtemp);
                    }
                }
                return;
            }

            if (fieldType == SystemTypes.Int16)
            {
                short value;
                if (termManager.TryGetI2Constant(fieldValue, out value))
                {
                    FieldValueHolder fvh = new FieldValueHolder(FieldValueType.SHORT);
                    fvh.shortValue = value;
                    expectedFieldValues.Add(field, fvh);
                }
                return;
            }

            if (fieldType == SystemTypes.Int64)
            {
                long value;
                if (termManager.TryGetI8Constant(fieldValue, out value))
                {
                    FieldValueHolder fvh = new FieldValueHolder(FieldValueType.LONG);
                    fvh.longValue = value;
                    expectedFieldValues.Add(field, fvh);
                }
                return;
            }

            if (field.Type.IsReferenceType)
            {
                Object obj = null;
                termManager.TryGetObject(fieldValue, out obj);
                FieldValueHolder fvh = new FieldValueHolder(FieldValueType.OBJECT);
                fvh.objValue = obj;
                expectedFieldValues.Add(field, fvh);

                //For reference value the actual value does not matter. However, without
                //proper entry in the acutal field, it would not considered for further processing
                if (allFieldsInCondition.Contains(field) && !actualFieldValues.Keys.Contains(field))
                {
                    FieldValueHolder fvhtemp = new FieldValueHolder(FieldValueType.OBJECT);
                    fvhtemp.objValue = null;
                    actualFieldValues.Add(field, fvhtemp);
                }

                return;
            }

            host.Log.LogWarning(WikiTopics.MissingWikiTopic, "TermSolver", "Expected values are computed only for integers, boolean and objects. Requires manual analysis of this sceanario");
        }