Beispiel #1
0
        /// <summary>
        /// Processes single merge operation - prepares all valid values and alias informations from the source indexes.
        /// When the source indexes contains some array values prepares operation for every descendant index and merge the
        /// array into one which will be stored in the target memory entry.
        /// </summary>
        /// <param name="operation">The operation.</param>
        private void processMergeOperation(MergeOperation operation)
        {
            HashSet <Value> values = new HashSet <Value>();

            foreach (var operationData in operation.Indexes)
            {
                MemoryIndex index    = operationData.Item1;
                Snapshot    snapshot = operationData.Item2;

                MemoryEntry entry = snapshot.Infos.GetMemoryEntry(index);
                HashSetTools.AddAll(values, entry.PossibleValues);
            }

            if (Structure.HasArray(operation.TargetIndex))
            {
                mergeArrays(operation);
            }

            if (operation.IsUndefined)
            {
                values.Add(targetSnapshot.UndefinedValue);
            }

            Structure.SetMemoryEntry(operation.TargetIndex, new MemoryEntry(values));
        }
Beispiel #2
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);
        }
Beispiel #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);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// Determines whether this container contains the same definitions as the given one.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns>True whether this container contains the same definitions as the given one.</returns>
        internal bool DataEquals(DeclarationContainer <T> other)
        {
            HashSet <QualifiedName> names = new HashSet <QualifiedName>();

            HashSetTools.AddAll(names, this.declarations.Keys);
            HashSetTools.AddAll(names, other.declarations.Keys);

            foreach (var name in names)
            {
                HashSet <T> otherDecl, thisDecl;
                if (!other.declarations.TryGetValue(name, out otherDecl))
                {
                    return(false);
                }

                if (!this.declarations.TryGetValue(name, out thisDecl))
                {
                    return(false);
                }

                if (!HashSetTools.EqualsSet(thisDecl, otherDecl))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #6
0
            /// <summary>
            /// Assigns new value into specified index.
            /// </summary>
            /// <param name="index">The index.</param>
            private void assign(MemoryIndex index)
            {
                HashSet <Value> newValues = new HashSet <Value>();

                if (!isMust)
                {
                    MemoryEntry oldEntry = snapshot.Structure.GetMemoryEntry(index);
                    HashSetTools.AddAll(newValues, oldEntry.PossibleValues);
                }

                HashSetTools.AddAll(newValues, entry.PossibleValues);

                snapshot.Structure.SetMemoryEntry(index, entry);
            }
Beispiel #7
0
            /// <summary>
            /// Visits the information value location.
            /// </summary>
            /// <param name="location">The location.</param>
            public void VisitInfoValueLocation(InfoValueLocation location)
            {
                MemoryEntry oldEntry = snapshot.Structure.GetMemoryEntry(location.ContainingIndex);

                HashSet <Value> newValues = new HashSet <Value>();

                HashSetTools.AddAll(newValues, oldEntry.PossibleValues);

                IEnumerable <Value> values = location.WriteValues(snapshot.MemoryAssistant, entry);

                newValues.Add(location.Value);

                snapshot.Structure.SetMemoryEntry(location.ContainingIndex, new MemoryEntry(newValues));
            }
Beispiel #8
0
        internal bool DataEquals(MemoryAlias other)
        {
            if (other == null)
            {
                return(this.MayAliasses.Count == 0 && this.MustAliasses.Count == 0);
            }

            if (this.MayAliasses.Count != other.MayAliasses.Count ||
                this.MustAliasses.Count != other.MustAliasses.Count)
            {
                return(false);
            }

            return(HashSetTools.EqualsSet(this.MustAliasses, other.MustAliasses) ||
                   HashSetTools.EqualsSet(this.MayAliasses, other.MayAliasses));
        }
Beispiel #9
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));
        }
Beispiel #10
0
        /// <summary>
        /// Simplifies memory entries which is bigget than simplify limit and compares data of this data collection object with the given one.
        /// </summary>
        /// <param name="oldData">The old data.</param>
        /// <param name="simplifyLimit">The simplify limit.</param>
        /// <param name="assistant">The assistant.</param>
        /// <returns>True whether compared data are the same.</returns>
        public bool DataEqualsAndSimplify(SnapshotData oldData, int simplifyLimit, MemoryAssistantBase assistant)
        {
            bool areEquals = true;

            HashSet <MemoryIndex> indexes = new HashSet <MemoryIndex>();

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

            foreach (MemoryIndex index in indexes)
            {
                if (!DataEqualsAndSimplify(oldData, index, simplifyLimit, assistant))
                {
                    areEquals = false;
                }
            }

            return(areEquals);
        }
Beispiel #11
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));
        }
Beispiel #12
0
        /// <summary>
        /// Compares data of this data collection object with the given one.
        /// </summary>
        /// <param name="oldData">The old data.</param>
        /// <returns>True whether compared data are the same.</returns>
        public bool DataEquals(SnapshotData oldData)
        {
            if (this.IndexData.Count != oldData.IndexData.Count)
            {
                return(false);
            }

            HashSet <MemoryIndex> indexes = new HashSet <MemoryIndex>();

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

            foreach (MemoryIndex index in indexes)
            {
                if (!DataEquals(oldData, index))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #13
0
        /// <summary>
        /// Adds the aliases to must or may lists of indexes.
        /// </summary>
        private void addAliasesToIndexes()
        {
            HashSet <MemoryIndex> mustAliases = new HashSet <MemoryIndex>();
            HashSet <MemoryIndex> mayAliases  = new HashSet <MemoryIndex>();

            foreach (MemoryIndex index in mustIndexesProcess)
            {
                MemoryAlias alias;
                if (snapshot.Structure.TryGetAliases(index, out alias))
                {
                    HashSetTools.AddAll(mustAliases, alias.MustAliasses);

                    foreach (MemoryIndex mayIndex in alias.MayAliasses)
                    {
                        mayAliases.Add(mayIndex);
                    }
                }
            }

            foreach (MemoryIndex index in mustAliases)
            {
                addToMust(index);
            }

            foreach (MemoryIndex index in mayIndexesProcess)
            {
                MemoryAlias alias;
                if (snapshot.Structure.TryGetAliases(index, out alias))
                {
                    HashSetTools.AddAll(mayAliases, alias.MustAliasses);
                    HashSetTools.AddAll(mayAliases, alias.MayAliasses);
                }
            }
            foreach (MemoryIndex index in mayAliases)
            {
                addToMay(index);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Reads the values from locations specified by given collector.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <returns>Memory entry with values from locations specified by given collector.</returns>
        public MemoryEntry ReadValue(IIndexCollector collector)
        {
            if (collector.MustIndexesCount == 1 && collector.IsDefined)
            {
                MemoryIndex index = collector.MustIndexes.First();
                return(snapshot.Structure.GetMemoryEntry(index));
            }
            else
            {
                HashSet <Value> values = new HashSet <Value>();
                if (!collector.IsDefined)
                {
                    values.Add(snapshot.UndefinedValue);
                }

                foreach (MemoryIndex index in collector.MustIndexes)
                {
                    MemoryEntry entry = snapshot.Structure.GetMemoryEntry(index);
                    HashSetTools.AddAll(values, entry.PossibleValues);
                }

                foreach (ValueLocation location in collector.MustLocation)
                {
                    if (snapshot.CurrentMode == SnapshotMode.MemoryLevel)
                    {
                        HashSetTools.AddAll(values, location.ReadValues(snapshot.MemoryAssistant));
                    }
                    else
                    {
                        InfoLocationVisitor visitor = new InfoLocationVisitor(snapshot);
                        location.Accept(visitor);
                        HashSetTools.AddAll(values, visitor.Value);
                    }
                }

                return(new MemoryEntry(values));
            }
        }
Beispiel #15
0
 /// <summary>
 /// Adds the must alias.
 /// </summary>
 /// <param name="aliases">The aliases.</param>
 internal void AddMustAlias(IEnumerable <MemoryIndex> aliases)
 {
     HashSetTools.AddAll(MustAliasses, aliases);
 }
Beispiel #16
0
 /// <summary>
 /// Sets all indexes to must.
 /// </summary>
 internal void SetAllToMust()
 {
     HashSetTools.AddAll(mustIndexes, mayIndexes);
     mayIndexes.Clear();
 }