示例#1
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");
        }