Ejemplo n.º 1
0
        /// <summary>
        /// Resolve method on current snapshot entry with given methodName
        /// </summary>
        /// <param name="context">Context where methods are resolved</param>
        /// <param name="methodName">Name of resolved method</param>
        /// <returns>
        /// Resolved methods
        /// </returns>
        protected override IEnumerable <FunctionValue> resolveMethod(SnapshotBase context, PHP.Core.QualifiedName methodName)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "resolve method - " + this.ToString() + " method: " + methodName);
            if (isTemporarySet(context))
            {
                return(getTemporary(context).ResolveMethod(context, methodName));
            }
            else
            {
                snapshot.Factories.Logger.Log(snapshot, "iterate fields: " + this.ToString());

                MemoryEntry values = readMemory(snapshot);

                snapshot.Factories.Benchmark.StartOperation(snapshot);

                snapshot.Factories.Benchmark.StartAlgorithm(snapshot, AlgorithmType.RESOLVE_METHOD);
                var methods = snapshot.Algorithms.ReadAlgorithm.GetMethod(snapshot, values, methodName);
                snapshot.Factories.Benchmark.FinishAlgorithm(snapshot, AlgorithmType.RESOLVE_METHOD);

                snapshot.Factories.Benchmark.FinishOperation(snapshot);

                return(methods);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Write given value at memory represented by snapshot entry
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="value">Written value</param>
        /// <param name="forceStrongWrite">Determine that current write should be processed as strong</param>
        /// <exception cref="System.NotSupportedException">Current mode:  + snapshot.CurrentMode</exception>
        protected override void writeMemory(SnapshotBase context, MemoryEntry value, bool forceStrongWrite)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "write memory - " + this.ToString());

            switch (snapshot.CurrentMode)
            {
            case SnapshotMode.MemoryLevel:
                getTemporary(context).WriteMemory(context, value, forceStrongWrite);
                break;

            case SnapshotMode.InfoLevel:
                if (isTemporarySet(context))
                {
                    getTemporary(context).WriteMemory(context, value, forceStrongWrite);
                }
                else
                {
                    infoEntry = value;
                }
                break;

            default:
                throw new NotSupportedException("Current mode: " + snapshot.CurrentMode);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read memory represented by current snapshot entry
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <returns>
        /// Memory represented by current snapshot entry
        /// </returns>
        /// <exception cref="System.NotSupportedException">Current mode:  + snapshot.CurrentMode</exception>
        protected override MemoryEntry readMemory(SnapshotBase context)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "read memory - " + this.ToString());

            if (isTemporarySet(context))
            {
                snapshot.Factories.Logger.Log(context, "read from temporary location - " + this.ToString());
                return(temporaryLocation.ReadMemory(context));
            }
            else
            {
                snapshot.Factories.Logger.Log(context, "read just value - " + this.ToString());
                switch (snapshot.CurrentMode)
                {
                case SnapshotMode.MemoryLevel:
                    return(dataEntry);

                case SnapshotMode.InfoLevel:
                    return(infoEntry);

                default:
                    throw new NotSupportedException("Current mode: " + snapshot.CurrentMode);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set aliases to current snapshot entry. Aliases can be set even to those entries
        /// that doesn't belongs to any variable, field,..
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="aliasedEntry">Snapshot entry which will be aliased from current entry</param>
        protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "set aliases - " + this.ToString());

            getTemporary(context).SetAliases(context, aliasedEntry);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Read memory represented by given field identifier resolved on current
        /// snapshot entry (resulting snapshot entry can encapsulate merging, alias resolving and
        /// other stuff based on nondeterminism of identifier and current snapshot entry)
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="field">Identifier of an field</param>
        /// <returns>
        /// Snapshot entry representing field resolving on current entry
        /// </returns>
        protected override ReadWriteSnapshotEntryBase readField(SnapshotBase context, AnalysisFramework.VariableIdentifier field)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "read index - " + this.ToString());

            return(getTemporary(context).ReadField(context, field));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Read memory represented by given index identifier resolved on current
        /// snapshot entry (resulting snapshot entry can encapsulate merging, alias resolving and
        /// other stuff based on nondeterminism of identifier and current snapshot entry)
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="index">Identifier of an index</param>
        /// <returns>
        /// Snapshot entry representing index resolving on current entry
        /// </returns>
        protected override ReadWriteSnapshotEntryBase readIndex(SnapshotBase context, MemberIdentifier index)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "read index - " + this.ToString());

            return(getTemporary(context).ReadIndex(context, index));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns aliases that can be used for making alias join
        /// to current snapshot entry
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <returns>
        /// Aliases of current snapshot entry
        /// </returns>
        protected override IEnumerable <AliasEntry> aliases(SnapshotBase context)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "aliases - " + this.ToString());

            if (isTemporarySet(context))
            {
                return(temporaryLocation.Aliases(context));
            }
            else
            {
                return(new AliasEntry[] { });
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Determine that memory represented by current snapshot entry Is already defined.
        /// If not, reading memory returns UndefinedValue. But UndefinedValue can be returned
        /// even for defined memory entries - this can be used to distinct
        /// between null/undefined semantic of PHP.
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <returns>True whether that memory represented by current snapshot entry Is already defined.</returns>
        protected override bool isDefined(SnapshotBase context)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "is defined - " + this.ToString());

            if (isTemporarySet(context))
            {
                return(temporaryLocation.IsDefined(context));
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 9
0
        /// <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();
                temporaryLocation = new SnapshotEntry(MemoryPath.MakePathTemporary(temporaryIndex));

                snapshot.Factories.Benchmark.StartAlgorithm(snapshot, AlgorithmType.MERGE_TO_TEMPORARY);
                snapshot.Algorithms.MergeAlgorithm.MergeMemoryEntry(snapshot, temporaryIndex, dataEntry);
                snapshot.Factories.Benchmark.FinishAlgorithm(snapshot, AlgorithmType.MERGE_TO_TEMPORARY);
            }

            return(temporaryLocation);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Resolve type of objects in snapshot entry
        /// </summary>
        /// <param name="context">Context where types are resolved</param>
        /// <returns>
        /// Resolved types
        /// </returns>
        protected override IEnumerable <TypeValue> resolveType(SnapshotBase context)
        {
            if (isTemporarySet(context))
            {
                return(getTemporary(context).ResolveType(context));
            }
            else
            {
                Snapshot snapshot = SnapshotEntry.ToSnapshot(context);
                snapshot.Factories.Logger.Log(snapshot, "iterate fields: " + this.ToString());

                MemoryEntry values = readMemory(snapshot);

                snapshot.Factories.Benchmark.StartAlgorithm(snapshot, AlgorithmType.RESOLVE_TYPE);
                var types = snapshot.Algorithms.ReadAlgorithm.GetObjectType(snapshot, values);
                snapshot.Factories.Benchmark.FinishAlgorithm(snapshot, AlgorithmType.RESOLVE_TYPE);

                return(types);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Iterate indexes defined on array
        /// </summary>
        /// <param name="context">Context where indexes are searched</param>
        /// <returns>
        /// Enumeration of available fields
        /// </returns>
        protected override IEnumerable <MemberIdentifier> iterateIndexes(SnapshotBase context)
        {
            if (isTemporarySet(context))
            {
                return(getTemporary(context).IterateIndexes(context));
            }
            else
            {
                Snapshot snapshot = SnapshotEntry.ToSnapshot(context);
                snapshot.Factories.Logger.Log(snapshot, "iterate fields: " + this.ToString());

                MemoryEntry values = readMemory(snapshot);

                snapshot.Factories.Benchmark.StartAlgorithm(snapshot, AlgorithmType.ITERATE_INDEXES);
                var indexes = snapshot.Algorithms.ReadAlgorithm.GetIndexes(snapshot, values);
                snapshot.Factories.Benchmark.FinishAlgorithm(snapshot, AlgorithmType.ITERATE_INDEXES);

                return(indexes);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Write given value at memory represented by snapshot entry and doesn't process any
        /// array copy. Is needed for correct increment/decrement semantic.
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="value">Written value</param>
        protected override void writeMemoryWithoutCopy(SnapshotBase context, MemoryEntry value)
        {
            if (isTemporarySet(context))
            {
                getTemporary(context).WriteMemoryWithoutCopy(context, value);
            }
            else
            {
                Snapshot snapshot = SnapshotEntry.ToSnapshot(context);
                switch (snapshot.CurrentMode)
                {
                case SnapshotMode.MemoryLevel:
                    dataEntry = value;
                    break;

                case SnapshotMode.InfoLevel:
                    infoEntry = value;
                    break;

                default:
                    throw new NotSupportedException("Current mode: " + snapshot.CurrentMode);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Determines whether there is associated temporary index with memory entry in the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>True whether there is associated temporary index with memory entry in the specified context.</returns>
        private bool isTemporarySet(SnapshotBase context)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            return(temporaryIndex != null && snapshot.IsTemporarySet(temporaryIndex));
        }