示例#1
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);
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VariableIndex"/> class.
 /// </summary>
 /// <param name="parentIndex">Index of the parent.</param>
 /// <param name="callLevel">The call level.</param>
 public VariableIndex(VariableIndex parentIndex, int callLevel)
     : base(parentIndex, callLevel)
 {
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VariableIndex"/> class.
 /// </summary>
 /// <param name="parentIndex">Index of the parent.</param>
 /// <param name="path">The path.</param>
 public VariableIndex(VariableIndex parentIndex, List <IndexSegment> path)
     : base(parentIndex, path)
 {
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VariableIndex"/> class.
 /// </summary>
 /// <param name="parentIndex">Index of the parent.</param>
 /// <param name="pathName">Name of the path.</param>
 public VariableIndex(VariableIndex parentIndex, IndexSegment pathName)
     : base(parentIndex, pathName)
 {
 }
示例#5
0
        /// <summary>
        /// Main method of merge algorithm.
        ///
        /// in first phase prepares new empty structure and data collections. Then collects all root memory locations
        /// and prepares their operations. As the final step process all merge operations which traverses the memory tree
        /// and creates new memory locations in target structure with the data from all source indexes.
        /// </summary>
        internal void Merge()
        {
            ContainerOperations[] collectVariables = new ContainerOperations[targetSnapshot.CallLevel + 1];
            ContainerOperations[] collectControl   = new ContainerOperations[targetSnapshot.CallLevel + 1];
            MergeOperation        returnOperation  = new MergeOperation();

            // Prepares empty structure for target snapshot
            for (int x = 0; x <= targetSnapshot.CallLevel; x++)
            {
                IndexContainer variables = new IndexContainer(VariableIndex.CreateUnknown(x));
                Structure.Variables[x] = variables;
                collectVariables[x]    = new ContainerOperations(this, variables, variables.UnknownIndex, variables.UnknownIndex);

                IndexContainer control = new IndexContainer(ControlIndex.CreateUnknown(x));
                Structure.ContolVariables[x] = control;
                collectControl[x]            = new ContainerOperations(this, control, control.UnknownIndex, control.UnknownIndex);

                Structure.Temporary[x] = new IndexSet <TemporaryIndex>();
                Structure.Arrays[x]    = new IndexSet <AssociativeArray>();
            }

            // Collects all objects and root locations from the source objects
            foreach (Snapshot snapshot in sourceSnapshots)
            {
                collectObjects(snapshot);

                for (int sourceLevel = 0, targetLevel = 0; targetLevel <= targetSnapshot.CallLevel; sourceLevel++, targetLevel++)
                {
                    // Local levels of snaphot has to be merged together no matter to call level of each snapshot.
                    if (sourceLevel == snapshot.CallLevel && snapshot.CallLevel != targetSnapshot.CallLevel)
                    {
                        if (isCallMerge)
                        {
                            // When this is the call merge the local level is forgotten
                            break;
                        }
                        else
                        {
                            targetLevel = targetSnapshot.CallLevel;
                        }
                    }

                    // Gets all root locations
                    collectVariables[targetLevel].CollectIndexes(snapshot, Structure.Variables[targetLevel].UnknownIndex, snapshot.Structure.Variables[sourceLevel]);
                    collectControl[targetLevel].CollectIndexes(snapshot, Structure.ContolVariables[targetLevel].UnknownIndex, snapshot.Structure.ContolVariables[sourceLevel]);
                    collectTemporary(snapshot, sourceLevel, targetLevel);
                }

                mergeDeclarations(Structure.FunctionDecl, snapshot.Structure.FunctionDecl);
                mergeDeclarations(Structure.ClassDecl, snapshot.Structure.ClassDecl);

                // When is it call merge remember which arrays was forgotten in order to support arrays in returns
                if (isCallMerge)
                {
                    foreach (AssociativeArray array in snapshot.Structure.Arrays.Local)
                    {
                        Structure.AddCallArray(array, snapshot);
                    }
                }
            }

            mergeObjects();

            // Prepares operations for all root locations
            for (int x = 0; x <= targetSnapshot.CallLevel; x++)
            {
                collectVariables[x].MergeContainers();
                collectControl[x].MergeContainers();
                mergeTemporary(x);
            }

            processMerge();

            // Build aliases
            foreach (var alias in memoryAliases)
            {
                Structure.SetAlias(alias.Key, alias.Value.Build());
            }
        }
示例#6
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);
        }