Exemple #1
0
        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));
        }