/// <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) { CollectComposedValuesVisitor visitor = new CollectComposedValuesVisitor(); ReferenceCollector references = new ReferenceCollector(); // Collect all data from source indexes foreach (var operationData in operation.Indexes) { MemoryIndex index = operationData.Item1; Snapshot snapshot = operationData.Item2; MemoryEntry entry = snapshot.Structure.GetMemoryEntry(index); visitor.VisitMemoryEntry(entry); MemoryAlias aliases; if (snapshot.Structure.TryGetAliases(index, out aliases)) { references.CollectMust(aliases.MustAliasses, targetSnapshot.CallLevel); references.CollectMay(aliases.MayAliasses, targetSnapshot.CallLevel); } else { references.InvalidateMust(); } } references.SetAliases(operation.TargetIndex, this, !operation.IsUndefined); //repares the set of values - array values are traversed HashSet <Value> values = getValues(operation, visitor); // If some index in operation can be undefined add undefined value into result if (operation.IsUndefined) { values.Add(targetSnapshot.UndefinedValue); } Structure.SetMemoryEntry(operation.TargetIndex, new MemoryEntry(values)); Structure.SetObjects(operation.TargetIndex, new ObjectValueContainer(visitor.Objects)); }
private void processMergeOperation(MergeOperation operation) { CollectComposedValuesVisitor visitor = new CollectComposedValuesVisitor(); ReferenceCollector references = new ReferenceCollector(); foreach (var item in operation.Indexes) { Snapshot snapshot = item.Item2; MemoryIndex index = item.Item1; MemoryEntry entry = snapshot.Structure.GetMemoryEntry(index); visitor.VisitMemoryEntry(entry); MemoryAlias aliases; if (snapshot.Structure.TryGetAliases(index, out aliases)) { references.CollectMust(aliases.MustAliasses, snapshot.CallLevel); references.CollectMay(aliases.MayAliasses, snapshot.CallLevel); } else { references.InvalidateMust(); } } if (references.HasAliases && !operation.IsRoot) { if (!operation.IsUndefined && operation.Indexes.Count == 1 && references.HasMustAliases) { if (targetSnapshot == operation.Indexes.First().Item2) { references.AddMustAlias(operation.Indexes.First().Item1); } } else { HashSet <MemoryIndex> referenceIndexes = new HashSet <MemoryIndex>(); foreach (var item in operation.Indexes) { MemoryIndex index = item.Item1; Snapshot snapshot = item.Item2; if (index != operation.TargetIndex && targetSnapshot == snapshot) { referenceIndexes.Add(index); } } references.CollectMay(referenceIndexes, targetSnapshot.CallLevel); } } references.SetAliases(operation.TargetIndex, targetSnapshot, !operation.IsUndefined); HashSet <Value> values = getValues(operation.TargetIndex, visitor, operation.IsUndefined); if (operation.IsUndefined) { values.Add(targetSnapshot.UndefinedValue); } targetSnapshot.Structure.SetMemoryEntry(operation.TargetIndex, new MemoryEntry(values)); }