示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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>
        public bool DataEqualsAndSimplify(SnapshotStructure oldValue, int simplifyLimit, MemoryAssistantBase assistant)
        {
            if (!compareDataAndSimplify(oldValue, simplifyLimit, assistant))
            {
                return(false);
            }

            return(compareDeclarations(oldValue));
        }
示例#5
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>
        public bool DataEquals(SnapshotStructure oldValue)
        {
            if (!compareData(oldValue))
            {
                return(false);
            }

            return(compareDeclarations(oldValue));
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MergeWorker"/> class.
        /// </summary>
        /// <param name="targetSnapshot">The target snapshot.</param>
        /// <param name="sourceSnapshots">The source snapshots.</param>
        /// <param name="isCallMerge">if set to <c>true</c> [is call merge].</param>
        public MergeWorker(Snapshot targetSnapshot, List <Snapshot> sourceSnapshots, bool isCallMerge = false)
        {
            Data           = SnapshotData.CreateEmpty(targetSnapshot);
            Structure      = SnapshotStructure.CreateEmpty(targetSnapshot);
            Structure.Data = Data;

            this.targetSnapshot  = targetSnapshot;
            this.sourceSnapshots = sourceSnapshots;
            this.isCallMerge     = isCallMerge;
        }
示例#7
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);
        }
示例#8
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>
        public bool WidenNotEqual(SnapshotStructure oldValue, int simplifyLimit, MemoryAssistantBase assistant)
        {
            lockedTest();

            bool funcCount  = this.FunctionDecl.Count == oldValue.FunctionDecl.Count;
            bool classCount = this.ClassDecl.Count == oldValue.ClassDecl.Count;

            if (!widenNotEqualData(oldValue, simplifyLimit, assistant))
            {
                return(false);
            }

            return(compareDeclarations(oldValue));
        }
示例#9
0
        /// <summary>
        /// Creates empty structure which contains no data in containers.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <returns>New empty structure which contains no data in containers.</returns>
        public static SnapshotStructure CreateEmpty(Snapshot snapshot)
        {
            SnapshotStructure data = new SnapshotStructure(snapshot);

            data.ArrayDescriptors  = new Dictionary <AssociativeArray, ArrayDescriptor>();
            data.ObjectDescriptors = new Dictionary <ObjectValue, ObjectDescriptor>();
            data.IndexData         = new Dictionary <MemoryIndex, IndexData>();

            data.Variables       = new VariableStack(snapshot.CallLevel);
            data.ContolVariables = new VariableStack(snapshot.CallLevel);
            data.FunctionDecl    = new DeclarationContainer <FunctionValue>();
            data.ClassDecl       = new DeclarationContainer <TypeValue>();

            data.Temporary  = new MemoryStack <IndexSet <TemporaryIndex> >(snapshot.CallLevel);
            data.Arrays     = new MemoryStack <IndexSet <AssociativeArray> >(snapshot.CallLevel);
            data.CallArrays = new Dictionary <AssociativeArray, IndexSet <Snapshot> >();

            return(data);
        }
示例#10
0
        /// <summary>
        ///  Creates new structure object as copy of this structure and adds new local level into memory stacks.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <param name="snapshotData">The snapshot data.</param>
        /// <returns>New copy of this structure and adds new local level into memory stacks.</returns>
        public SnapshotStructure CopyAndAddLocalLevel(Snapshot snapshot, SnapshotData snapshotData)
        {
            SnapshotStructure data = new SnapshotStructure(snapshot);

            data.Data = snapshotData;

            data.ArrayDescriptors  = new Dictionary <AssociativeArray, ArrayDescriptor>(ArrayDescriptors);
            data.ObjectDescriptors = new Dictionary <ObjectValue, ObjectDescriptor>(ObjectDescriptors);
            data.IndexData         = new Dictionary <MemoryIndex, IndexData>(IndexData);
            data.FunctionDecl      = new DeclarationContainer <FunctionValue>(FunctionDecl);
            data.ClassDecl         = new DeclarationContainer <TypeValue>(ClassDecl);

            data.Variables       = new VariableStack(Variables, data.createIndexContainer(VariableIndex.CreateUnknown(Variables.Length)));
            data.ContolVariables = new VariableStack(ContolVariables, data.createIndexContainer(ControlIndex.CreateUnknown(ContolVariables.Length)));

            data.Temporary  = new MemoryStack <IndexSet <TemporaryIndex> >(Temporary, new IndexSet <TemporaryIndex>());
            data.Arrays     = new MemoryStack <IndexSet <AssociativeArray> >(Arrays, new IndexSet <AssociativeArray>());
            data.CallArrays = new Dictionary <AssociativeArray, IndexSet <Snapshot> >(CallArrays);

            return(data);
        }
示例#11
0
        /// <summary>
        /// Creates new structure object as copy of this structure which contains the same data as this instace.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <param name="snapshotData">The snapshot data.</param>
        /// <returns>New copy of this structure which contains the same data as this instace.</returns>
        public SnapshotStructure Copy(Snapshot snapshot, SnapshotData snapshotData)
        {
            SnapshotStructure data = new SnapshotStructure(snapshot);

            data.Data = snapshotData;

            data.ArrayDescriptors  = new Dictionary <AssociativeArray, ArrayDescriptor>(ArrayDescriptors);
            data.ObjectDescriptors = new Dictionary <ObjectValue, ObjectDescriptor>(ObjectDescriptors);
            data.IndexData         = new Dictionary <MemoryIndex, IndexData>(IndexData);
            data.FunctionDecl      = new DeclarationContainer <FunctionValue>(FunctionDecl);
            data.ClassDecl         = new DeclarationContainer <TypeValue>(ClassDecl);

            data.Variables       = new VariableStack(Variables);
            data.ContolVariables = new VariableStack(ContolVariables);

            data.Temporary  = new MemoryStack <IndexSet <TemporaryIndex> >(Temporary);
            data.Arrays     = new MemoryStack <IndexSet <AssociativeArray> >(Arrays);
            data.CallArrays = new Dictionary <AssociativeArray, IndexSet <Snapshot> >(CallArrays);

            return(data);
        }
示例#12
0
        /// <summary>
        /// Creates the structure with memory stack with global level only.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <param name="snapshotData">The snapshot data.</param>
        /// <returns>New structure with memory stack with global level only.</returns>
        public static SnapshotStructure CreateGlobal(Snapshot snapshot, SnapshotData snapshotData)
        {
            SnapshotStructure data = new SnapshotStructure(snapshot);

            data.Data = snapshotData;

            data.ArrayDescriptors  = new Dictionary <AssociativeArray, ArrayDescriptor>();
            data.ObjectDescriptors = new Dictionary <ObjectValue, ObjectDescriptor>();
            data.IndexData         = new Dictionary <MemoryIndex, IndexData>();

            data.Variables       = data.createMemoryStack(VariableIndex.CreateUnknown(Snapshot.GLOBAL_CALL_LEVEL));
            data.ContolVariables = data.createMemoryStack(ControlIndex.CreateUnknown(Snapshot.GLOBAL_CALL_LEVEL));
            data.FunctionDecl    = new DeclarationContainer <FunctionValue>();
            data.ClassDecl       = new DeclarationContainer <TypeValue>();

            data.Temporary  = new MemoryStack <IndexSet <TemporaryIndex> >(new IndexSet <TemporaryIndex>());
            data.Arrays     = new MemoryStack <IndexSet <AssociativeArray> >(new IndexSet <AssociativeArray>());
            data.CallArrays = new Dictionary <AssociativeArray, IndexSet <Snapshot> >();

            return(data);
        }
示例#13
0
        /// <summary>
        /// Compares the declarations of functions and classes whether there is some structural changes between this and old structure object.
        /// </summary>
        /// <param name="oldValue">The old value.</param>
        /// <returns><c>true</c> if the data are same; otherwise, <c>false</c>.</returns>
        private bool compareDeclarations(SnapshotStructure oldValue)
        {
            bool funcCount  = this.FunctionDecl.Count == oldValue.FunctionDecl.Count;
            bool classCount = this.ClassDecl.Count == oldValue.ClassDecl.Count;

            if (classCount && funcCount)
            {
                if (!this.FunctionDecl.DataEquals(oldValue.FunctionDecl))
                {
                    return(false);
                }

                if (!this.ClassDecl.DataEquals(oldValue.ClassDecl))
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }