Esempio n. 1
0
        /// <summary>
        /// Compares this structure object with given copy of old data and applies simplify limit when new memory entry is bigger than given simplify limit.
        /// </summary>
        /// <param name="oldValue">The old value.</param>
        /// <param name="simplifyLimit">The simplify limit.</param>
        /// <param name="assistant">The assistant.</param>
        /// <returns><c>true</c> if the data are same; otherwise, <c>false</c>.</returns>
        private bool compareDataAndSimplify(SnapshotStructure oldValue, int simplifyLimit, MemoryAssistantBase assistant)
        {
            HashSet <MemoryIndex> usedIndexes = new HashSet <MemoryIndex>();

            HashSetTools.AddAll(usedIndexes, this.IndexData.Keys);
            HashSetTools.AddAll(usedIndexes, oldValue.IndexData.Keys);

            IndexData emptyStructure = new CopyMemoryModel.IndexData(null, null, null);

            bool areEqual = true;

            foreach (MemoryIndex index in usedIndexes)
            {
                if (index is TemporaryIndex)
                {
                    continue;
                }
                IndexData newStructure = getDataOrUndefined(index, this, emptyStructure);
                IndexData oldStructure = getDataOrUndefined(index, oldValue, emptyStructure);

                if (!newStructure.DataEquals(oldStructure))
                {
                    areEqual = false;
                }

                if (!Data.DataEqualsAndSimplify(oldValue.Data, index, simplifyLimit, assistant))
                {
                    areEqual = false;
                }
            }

            return(areEqual);
        }
Esempio n. 2
0
        /// <summary>
        /// Compares this data structure with the given object.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns>True whether this instance contains the same values as the given one.</returns>
        internal bool DataEquals(IndexData other)
        {
            if (this == other)
            {
                return(true);
            }

            if (this.Aliases != other.Aliases)
            {
                if (!MemoryAlias.AreEqual(Aliases, other.Aliases))
                {
                    return(false);
                }
            }

            if (this.Array != other.Array)
            {
                if (Array == null || other.Array == null || !this.Array.Equals(other.Array))
                {
                    return(false);
                }
            }

            if (this.Objects != other.Objects)
            {
                if (!ObjectValueContainer.AreEqual(Objects, other.Objects))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Compares this structure object with given copy of old data.
        /// </summary>
        /// <param name="oldValue">The old value.</param>
        /// <returns><c>true</c> if the data are same; otherwise, <c>false</c>.</returns>
        private bool compareData(SnapshotStructure oldValue)
        {
            HashSet <MemoryIndex> usedIndexes = new HashSet <MemoryIndex>();

            HashSetTools.AddAll(usedIndexes, this.IndexData.Keys);
            HashSetTools.AddAll(usedIndexes, oldValue.IndexData.Keys);

            IndexData emptyStructure = new CopyMemoryModel.IndexData(null, null, null);

            foreach (MemoryIndex index in usedIndexes)
            {
                if (index is TemporaryIndex)
                {
                    continue;
                }
                IndexData newStructure = getDataOrUndefined(index, this, emptyStructure);
                IndexData oldStructure = getDataOrUndefined(index, oldValue, emptyStructure);

                if (!newStructure.DataEquals(oldStructure))
                {
                    return(false);
                }

                if (!Data.DataEquals(oldValue.Data, index))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the array for specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="arrayValue">The array value.</param>
        internal void SetArray(MemoryIndex index, AssociativeArray arrayValue)
        {
            lockedTest();

            IndexData data;

            if (!IndexData.TryGetValue(index, out data))
            {
                data = new IndexData(null, null, null);
            }

            IndexDataBuilder builder = data.Builder();

            builder.Array = arrayValue;

            IndexData[index] = builder.Build();

            ArrayDescriptor descriptor;

            if (TryGetDescriptor(arrayValue, out descriptor))
            {
                if (descriptor.ParentVariable != null)
                {
                    Arrays[descriptor.ParentVariable.CallLevel].Remove(arrayValue);
                }
            }
            Arrays[index.CallLevel].Add(arrayValue);
        }
Esempio n. 5
0
        /// <summary>
        /// Compares this structure object with given copy of old data and applies widening operation on memory entry which differs.
        /// </summary>
        /// <param name="oldValue">The old value.</param>
        /// <param name="simplifyLimit">The simplify limit.</param>
        /// <param name="assistant">The assistant.</param>
        /// <returns><c>true</c> if the data are same; otherwise, <c>false</c>.</returns>
        private bool widenNotEqualData(SnapshotStructure oldValue, int simplifyLimit, MemoryAssistantBase assistant)
        {
            HashSet <MemoryIndex> indexes = new HashSet <MemoryIndex>();

            HashSetTools.AddAll(indexes, this.IndexData.Keys);
            HashSetTools.AddAll(indexes, oldValue.IndexData.Keys);

            IndexData emptyData = new CopyMemoryModel.IndexData(null, null, null);

            bool areEqual = true;

            foreach (MemoryIndex index in indexes)
            {
                if (index is TemporaryIndex)
                {
                    continue;
                }

                IndexData newData = getDataOrUndefined(index, this, emptyData);
                IndexData oldData = getDataOrUndefined(index, oldValue, emptyData);

                Data.DataWiden(oldValue.Data, index, assistant);

                if (!Data.DataEqualsAndSimplify(oldValue.Data, index, simplifyLimit, assistant))
                {
                    areEqual = false;
                }
            }

            return(areEqual);
        }
Esempio n. 6
0
        /// <summary>
        /// Removes the index from structure and data.
        /// </summary>
        /// <param name="index">The index.</param>
        internal void RemoveIndex(MemoryIndex index)
        {
            lockedTest();

            IndexData.Remove(index);
            Data.RemoveMemoryEntry(index);
        }
Esempio n. 7
0
        /// <summary>
        /// Insert newly created index into structure and data collection.
        /// </summary>
        /// <param name="index">The index.</param>
        internal void NewIndex(MemoryIndex index)
        {
            lockedTest();

            IndexData data = new IndexData(null, null, null);

            IndexData[index] = data;
            Data.SetMemoryEntry(index, new MemoryEntry(Snapshot.UndefinedValue));
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the data of specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>Data of specified index.</returns>
        /// <exception cref="System.Exception">Missing alias value for given index</exception>
        internal IndexData GetIndexData(MemoryIndex index)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                return(data);
            }
            throw new Exception("Missing alias value for " + index);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the data is set in structure or returns given empty data.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="snapshotStructure">The snapshot structure.</param>
        /// <param name="emptyData">The empty data.</param>
        /// <returns>Data is set in structure or returns given empty data.</returns>
        private CopyMemoryModel.IndexData getDataOrUndefined(MemoryIndex index, SnapshotStructure snapshotStructure, IndexData emptyData)
        {
            IndexData data = null;

            if (!snapshotStructure.IndexData.TryGetValue(index, out data))
            {
                data = emptyData;
            }

            return(data);
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the aliases for specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>Aliases for the specified index.</returns>
        /// <exception cref="System.Exception">Missing alias value for  + index</exception>
        internal MemoryAlias GetAliases(MemoryIndex index)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                if (data.Aliases != null)
                {
                    return(data.Aliases);
                }
            }
            throw new Exception("Missing alias value for " + index);
        }
Esempio n. 11
0
        /// <summary>
        /// Determines whether the specified index has array.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>True whether the specified index has array.</returns>
        internal bool HasArray(MemoryIndex index)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                return(data.Array != null);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Gets the array descriptor which contains information about defined indexes in the specified array.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>Array descriptor which contains information about defined indexes in the specified array.</returns>
        /// <exception cref="System.Exception">Missing array for index  + index</exception>
        internal AssociativeArray GetArray(MemoryIndex index)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                if (data.Array != null)
                {
                    return(data.Array);
                }
            }

            throw new Exception("Missing array for index " + index);
        }
Esempio n. 13
0
        /// <summary>
        /// Gets the objects for given index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>Collection of objects for given index.</returns>
        public ObjectValueContainer GetObjects(MemoryIndex index)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                if (data.Objects != null)
                {
                    return(data.Objects);
                }
            }

            return(new ObjectValueContainer());
        }
Esempio n. 14
0
        /// <summary>
        /// Sets the memory entry to actual index data collection.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="memoryEntry">The memory entry.</param>
        internal void SetMemoryEntry(MemoryIndex index, MemoryEntry memoryEntry)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                Data.SetMemoryEntry(index, memoryEntry);
            }
            else if (!Locked)
            {
                IndexData[index] = new IndexData(null, null, null);
                Data.SetMemoryEntry(index, memoryEntry);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Tries the get aliases for specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="aliases">The aliases.</param>
        /// <returns>True whether specified index has aliases.</returns>
        internal bool TryGetAliases(MemoryIndex index, out MemoryAlias aliases)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                aliases = data.Aliases;
                return(data.Aliases != null);
            }
            else
            {
                aliases = null;
                return(false);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Tries to get array for specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="arrayValue">The array value.</param>
        /// <returns>True whether the specified index has array.</returns>
        internal bool TryGetArray(MemoryIndex index, out AssociativeArray arrayValue)
        {
            IndexData data;

            if (IndexData.TryGetValue(index, out data))
            {
                arrayValue = data.Array;
                return(data.Array != null);
            }
            else
            {
                arrayValue = null;
                return(false);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Sets objects for given index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="objects">The objects.</param>
        internal void SetObjects(MemoryIndex index, ObjectValueContainer objects)
        {
            lockedTest();

            IndexData data;

            if (!IndexData.TryGetValue(index, out data))
            {
                data = new IndexData(null, null, null);
            }

            IndexDataBuilder builder = data.Builder();

            builder.Objects = objects;

            IndexData[index] = builder.Build();
        }
Esempio n. 18
0
        /// <summary>
        /// Removes the alias from specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        internal void RemoveAlias(MemoryIndex index)
        {
            lockedTest();

            IndexData data;

            if (!IndexData.TryGetValue(index, out data))
            {
                data = new IndexData(null, null, null);
            }

            IndexDataBuilder builder = data.Builder();

            builder.Aliases = null;

            IndexData[index] = builder.Build();
        }
Esempio n. 19
0
        /// <summary>
        /// Assigns the may memory index.
        /// </summary>
        /// <param name="mayIndex">Index of the may.</param>
        /// <param name="composedValues">The composed values.</param>
        private void assignMay(MemoryIndex mayIndex, CollectComposedValuesVisitor composedValues)
        {
            IndexData       data   = snapshot.Structure.GetIndexData(mayIndex);
            HashSet <Value> values = new HashSet <Value>(composedValues.Values);

            if (composedValues.Objects.Count > 0)
            {
                HashSet <ObjectValue> objects = new HashSet <ObjectValue>(data.Objects);
                HashSetTools.AddAll(objects, composedValues.Objects);
                snapshot.Structure.SetObjects(mayIndex, new ObjectValueContainer(objects));

                //if (data.Objects != null)
                HashSetTools.AddAll(values, data.Objects);
            }

            HashSetTools.AddAll(values, snapshot.Structure.GetMemoryEntry(mayIndex).PossibleValues);
            snapshot.Structure.SetMemoryEntry(mayIndex, new MemoryEntry(values));
        }
Esempio n. 20
0
        /// <summary>
        /// Removes the array from specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="arrayValue">The array value.</param>
        internal void RemoveArray(MemoryIndex index, AssociativeArray arrayValue)
        {
            lockedTest();

            ArrayDescriptors.Remove(arrayValue);

            IndexData data;

            if (!IndexData.TryGetValue(index, out data))
            {
                data = new IndexData(null, null, null);
            }

            IndexDataBuilder builder = data.Builder();

            builder.Array = null;

            IndexData[index] = builder.Build();
            Arrays[index.CallLevel].Remove(arrayValue);
        }
Esempio n. 21
0
        /// <summary>
        /// Assigns the must memory index.
        /// </summary>
        /// <param name="mustIndex">Index of the must.</param>
        /// <param name="composedValues">The composed values.</param>
        private void assignMust(MemoryIndex mustIndex, CollectComposedValuesVisitor composedValues)
        {
            IndexData       data   = snapshot.Structure.GetIndexData(mustIndex);
            HashSet <Value> values = new HashSet <Value>(composedValues.Values);

            if (data.Array != null)
            {
                values.Add(data.Array);
            }

            if (composedValues.Objects.Count > 0)
            {
                snapshot.Structure.SetObjects(mustIndex, new ObjectValueContainer(composedValues.Objects));
                if (data.Objects != null)
                {
                    HashSetTools.AddAll(values, data.Objects);
                }
            }

            snapshot.Structure.SetMemoryEntry(mustIndex, new MemoryEntry(values));
        }
Esempio n. 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IndexDataBuilder"/> class.
 /// </summary>
 /// <param name="data">The data.</param>
 public IndexDataBuilder(IndexData data)
 {
     Aliases = data.Aliases;
     Array   = data.Array;
     Objects = data.Objects;
 }
Esempio n. 23
0
 /// <summary>
 /// Determines whether the specified index is defined.
 /// </summary>
 /// <param name="index">The index.</param>
 internal bool IsDefined(MemoryIndex index)
 {
     return(IndexData.ContainsKey(index));
 }
Esempio n. 24
0
 /// <summary>
 /// Tries to get data of given index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="data">The data.</param>
 /// <returns><c>true</c> if the data are same; otherwise, <c>false</c>.</returns>
 internal bool TryGetIndexData(MemoryIndex index, out IndexData data)
 {
     return(IndexData.TryGetValue(index, out data));
 }