/// <summary> /// Creates the alias to this entry and returnes data which can be used to aliasing the target. /// </summary> /// <param name="snapshot">The snapshot.</param> /// <returns> /// Alias data fro the newly created aliases. /// </returns> public AliasData CreateAliasToEntry(Snapshot snapshot) { //Collect alias indexes AssignCollector indexesCollector = new AssignCollector(snapshot); indexesCollector.ProcessPath(path); //Memory locations where to get data from ReadCollector valueCollector = new ReadCollector(snapshot); valueCollector.ProcessPath(path); //Get data from locations ReadWorker worker = new ReadWorker(snapshot); MemoryEntry value = worker.ReadValue(valueCollector); //Makes deep copy of data to prevent changes after assign alias TemporaryIndex temporaryIndex = snapshot.CreateTemporary(); MergeWithinSnapshotWorker mergeWorker = new MergeWithinSnapshotWorker(snapshot); mergeWorker.MergeMemoryEntry(temporaryIndex, value); AliasData data = new AliasData(indexesCollector.MustIndexes, indexesCollector.MayIndexes, temporaryIndex); data.TemporaryIndexToRealease(temporaryIndex); return(data); }
/// <summary> /// Assigns the specified collector. /// </summary> /// <param name="collector">The collector.</param> /// <param name="sourceIndex">Index of the source.</param> internal void Assign(IIndexCollector collector, MemoryIndex sourceIndex) { foreach (MemoryIndex mustIndex in collector.MustIndexes) { snapshot.DestroyMemory(mustIndex); CopyWithinSnapshotWorker copyWorker = new CopyWithinSnapshotWorker(snapshot, true); copyWorker.Copy(sourceIndex, mustIndex); } foreach (MemoryIndex mayIndex in collector.MayIndexes) { MergeWithinSnapshotWorker mergeWorker = new MergeWithinSnapshotWorker(snapshot); mergeWorker.MergeIndexes(mayIndex, sourceIndex); } MemoryEntry entry = snapshot.Structure.GetMemoryEntry(sourceIndex); LocationVisitor mustVisitor = new LocationVisitor(snapshot, entry, true); foreach (ValueLocation location in collector.MustLocation) { location.Accept(mustVisitor); } LocationVisitor mayVisitor = new LocationVisitor(snapshot, entry, false); foreach (ValueLocation location in collector.MayLocaton) { location.Accept(mayVisitor); } }
/// <summary> /// Gets the snapshot entry of temporary index associated with this memory entry. /// </summary> /// <param name="context">The context.</param> private SnapshotEntry getTemporary(SnapshotBase context) { Snapshot snapshot = SnapshotEntry.ToSnapshot(context); if (temporaryLocation == null) { temporaryIndex = snapshot.CreateTemporary(); MergeWithinSnapshotWorker mergeWorker = new MergeWithinSnapshotWorker(snapshot); mergeWorker.MergeMemoryEntry(temporaryIndex, dataEntry); temporaryLocation = new SnapshotEntry(MemoryPath.MakePathTemporary(temporaryIndex)); } return(temporaryLocation); }
/// <summary> /// Writes the memory normal. /// </summary> /// <param name="snapshot">The snapshot.</param> /// <param name="value">The value.</param> /// <param name="forceStrongWrite">if set to <c>true</c> [force strong write].</param> private void writeMemoryNormal(Snapshot snapshot, MemoryEntry value, bool forceStrongWrite) { TemporaryIndex temporaryIndex = snapshot.CreateTemporary(); MergeWithinSnapshotWorker mergeWorker = new MergeWithinSnapshotWorker(snapshot); mergeWorker.MergeMemoryEntry(temporaryIndex, value); AssignCollector collector = new AssignCollector(snapshot); collector.ProcessPath(path); if (forceStrongWrite) { collector.SetAllToMust(); } AssignWorker worker = new AssignWorker(snapshot); worker.Assign(collector, temporaryIndex); snapshot.ReleaseTemporary(temporaryIndex); }