/// <summary> /// Creates the merge operation for all fields of specified object. /// </summary> /// <param name="objectValue">The object value.</param> private void mergeObject(ObjectValue objectValue) { ObjectDescriptorBuilder builder = new ObjectDescriptor(objectValue, null, ObjectIndex.CreateUnknown(objectValue)) .Builder(); ContainerOperations collectVariables = new ContainerOperations(this, builder, builder.UnknownIndex, builder.UnknownIndex); foreach (Snapshot snapshot in sourceSnapshots) { ObjectDescriptor descriptor; if (snapshot.Structure.TryGetDescriptor(objectValue, out descriptor)) { collectVariables.CollectIndexes(snapshot, builder.UnknownIndex, descriptor); builder.Type = descriptor.Type; } else { collectVariables.SetUndefined(); } } collectVariables.MergeContainers(); Structure.ObjectDescriptors.Add(objectValue, builder.Build()); }
/// <summary> /// Prepares operation for every descendant index of target array. /// </summary> /// <param name="operation">The operation.</param> /// <returns>Array where the input arrays is merged into.</returns> private void mergeArrays(MergeOperation operation) { AssociativeArray targetArray = Structure.GetArray(operation.TargetIndex); ArrayDescriptor targetDescriptor = Structure.GetDescriptor(targetArray); ContainerOperations collectIndexes = new ContainerOperations(this, targetDescriptor.Builder(), operation.TargetIndex, targetDescriptor.UnknownIndex); foreach (var operationData in operation.Indexes) { MemoryIndex index = operationData.Item1; Snapshot snapshot = operationData.Item2; AssociativeArray arrayValue; if (snapshot.Structure.TryGetArray(index, out arrayValue)) { ArrayDescriptor descriptor = snapshot.Structure.GetDescriptor(arrayValue); collectIndexes.AddContainer(descriptor, snapshot); } else { collectIndexes.SetUndefined(); } } collectIndexes.MergeContainers(); }
/// <summary> /// 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> /// <returns>Array where the input arrays is merged into.</returns> private Value mergeArrays(MergeOperation operation) { ArrayDescriptorBuilder builder = new ArrayDescriptorBuilder(); builder.SetParentVariable(operation.TargetIndex); builder.SetUnknownField(operation.TargetIndex.CreateUnknownIndex()); ContainerOperations collectVariables = new ContainerOperations(this, builder, operation.TargetIndex, builder.UnknownIndex); // Collecting possible indexes of merged array AssociativeArray targetArray = null; foreach (var operationData in operation.Indexes) { MemoryIndex index = operationData.Item1; Snapshot snapshot = operationData.Item2; AssociativeArray arrayValue; if (snapshot.Structure.TryGetArray(index, out arrayValue)) { // Target array value will be the firs one if (targetArray == null) { if (index.Equals(operation.TargetIndex)) { targetArray = arrayValue; } } ArrayDescriptor descriptor = snapshot.Structure.GetDescriptor(arrayValue); collectVariables.CollectIndexes(snapshot, index, descriptor); } else { collectVariables.SetUndefined(); } } if (targetArray == null) { targetArray = targetSnapshot.CreateArray(); } builder.SetArrayValue(targetArray); collectVariables.MergeContainers(); Structure.SetArray(operation.TargetIndex, targetArray); Structure.SetDescriptor(targetArray, builder.Build()); return(targetArray); }
/// <summary> /// Creates the merge operation for all fields of specified object. /// </summary> /// <param name="objectValue">The object value.</param> private void mergeObject(ObjectValue objectValue) { ObjectDescriptor targetDescriptor = Structure.GetDescriptor(objectValue); ContainerOperations collectVariables = new ContainerOperations(this, targetDescriptor.Builder(), targetDescriptor.UnknownIndex, targetDescriptor.UnknownIndex); foreach (Snapshot snapshot in sourceSnapshots) { ObjectDescriptor descriptor; if (snapshot.Structure.TryGetDescriptor(objectValue, out descriptor)) { collectVariables.AddContainer(descriptor, snapshot); } else { collectVariables.SetUndefined(); } } collectVariables.MergeContainers(); }