예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldLocationVisitor"/> class.
 /// </summary>
 /// <param name="fieldSegment">The field segment.</param>
 /// <param name="assistant">The assistant.</param>
 /// <param name="mustLocationProcess">The must location process.</param>
 /// <param name="mayLocationProcess">The may location process.</param>
 public FieldLocationVisitor(FieldPathSegment fieldSegment, MemoryAssistantBase assistant, HashSet <ValueLocation> mustLocationProcess, HashSet <ValueLocation> mayLocationProcess)
     : base(assistant)
 {
     this.fieldSegment        = fieldSegment;
     this.mustLocationProcess = mustLocationProcess;
     this.mayLocationProcess  = mayLocationProcess;
 }
예제 #2
0
 public void VisitField(FieldPathSegment fieldSegment)
 {
     foreach (LocationCollectorNode node in currentNodes)
     {
         node.CollectField(this, fieldSegment);
     }
 }
예제 #3
0
 public FieldLocationVisitor(TreeIndexCollector collector, FieldPathSegment fieldSegment,
                             ValueCollectorNode node)
     : base(collector.Snapshot.MemoryAssistant)
 {
     this.collector    = collector;
     this.fieldSegment = fieldSegment;
     this.node         = node;
 }
예제 #4
0
        /// <summary>
        /// Collects the field segment from values.
        /// </summary>
        /// <param name="fieldSegment">The field segment.</param>
        /// <param name="node">The node.</param>
        /// <param name="values">The values.</param>
        /// <param name="isMust">if set to <c>true</c> [is must].</param>
        public void CollectFieldSegmentFromValues(FieldPathSegment fieldSegment, CollectorNode node,
                                                  IEnumerable <Value> values, bool isMust)
        {
            isMust = isMust && values.Count() == 1;
            CollectFieldValueVisitor visitor = new CollectFieldValueVisitor(fieldSegment, this, node, isMust);

            visitor.VisitValues(values);
        }
예제 #5
0
        public CollectFieldValueVisitor(FieldPathSegment fieldSegment, TreeIndexCollector treeIndexCollector, CollectorNode node, bool isMust)
        {
            this.fieldSegment       = fieldSegment;
            this.treeIndexCollector = treeIndexCollector;
            this.node   = node;
            this.isMust = isMust;

            index = new VariableIdentifier(fieldSegment.Names);
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadFieldVisitor"/> class.
        /// </summary>
        /// <param name="containingIndex">Index of the containing.</param>
        /// <param name="fieldSegment">The field segment.</param>
        /// <param name="locations">The locations.</param>
        public ReadFieldVisitor(MemoryIndex containingIndex, FieldPathSegment fieldSegment, ICollection <ValueLocation> locations)
        {
            this.containingIndex = containingIndex;
            this.locations       = locations;

            ContainsUndefinedValue = false;
            ContainsDefinedValue   = false;
            ContainsObjectValue    = false;
            ContainsAnyValue       = false;

            index = new VariableIdentifier(fieldSegment.Names);
        }
예제 #7
0
        /// <summary>
        /// Visits the field to continue traversing memory tree by object field.
        /// </summary>
        /// <param name="fieldSegment">The field segment.</param>
        public void VisitField(FieldPathSegment fieldSegment)
        {
            FieldLocationVisitor visitor = new FieldLocationVisitor(fieldSegment, this);

            foreach (MemoryIndex parentIndex in mustIndexes)
            {
                processField(parentIndex, fieldSegment, visitor);
            }

            foreach (ValueLocation parentLocation in mustLocation)
            {
                parentLocation.Accept(visitor);
            }
        }
예제 #8
0
        /// <summary>
        /// Collects the index of the field from memory.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <param name="fieldSegment">The field segment.</param>
        /// <param name="index">The index.</param>
        protected void collectFieldFromMemoryIndex(TreeIndexCollector collector, FieldPathSegment fieldSegment, MemoryIndex index)
        {
            MemoryEntry entry = collector.GetMemoryEntry(index);

            this.ContainsUndefinedValue = entry.ContainsUndefinedValue;
            bool processOtherValues = false;

            IObjectValueContainer objects = collector.Structure.GetObjects(index);

            if (objects.Count > 0)
            {
                processOtherValues = entry.Count > objects.Count ||
                                     entry.ContainsUndefinedValue && entry.Count > objects.Count + 1;

                bool isMustObject = objects.Count == 1 && !processOtherValues && !entry.ContainsUndefinedValue;
                foreach (var objectValue in objects)
                {
                    collector.RootNode.CollectObject(collector, objectValue, fieldSegment);
                }

                if (entry.ContainsUndefinedValue)
                {
                    AddNewImplicitObjectNode(false);
                    collector.CollectSegmentWithoutStructure(fieldSegment, ImplicitObjectNode, false);
                }
            }
            else if (entry.ContainsUndefinedValue)
            {
                processOtherValues = entry.Count > 1;

                AddNewImplicitObjectNode(!processOtherValues);
                collector.CollectSegmentWithoutStructure(fieldSegment, ImplicitObjectNode, !processOtherValues);
            }
            else
            {
                processOtherValues = true;
            }

            if (processOtherValues)
            {
                collector.CollectFieldSegmentFromValues(fieldSegment, this, entry.PossibleValues, true);
            }
        }
예제 #9
0
        /// <summary>
        /// Processes the field - traverse thru all containing objects or sets path to undefined.
        /// </summary>
        /// <param name="parentIndex">Index of the parent.</param>
        /// <param name="fieldSegment">The field segment.</param>
        /// <param name="visitor">The visitor to process scalar values.</param>
        private void processField(MemoryIndex parentIndex, FieldPathSegment fieldSegment, ProcessValueAsLocationVisitor visitor)
        {
            MemoryEntry entry;

            if (snapshot.Data.Readonly.TryGetMemoryEntry(parentIndex, out entry))
            {
                bool processOtherValues            = false;
                IObjectValueContainer objectValues = snapshot.Structure.Readonly.GetObjects(parentIndex);
                if (objectValues.Count > 0)
                {
                    foreach (ObjectValue objectValue in objectValues)
                    {
                        IObjectDescriptor descriptor = snapshot.Structure.Readonly.GetDescriptor(objectValue);
                        process(fieldSegment, descriptor);
                    }

                    processOtherValues = entry.Count > objectValues.Count;
                }
                else if (entry.Count > 0)
                {
                    processOtherValues = true;
                }
                else
                {
                    IsDefined = false;
                }

                if (processOtherValues)
                {
                    visitor.ProcessValues(parentIndex, entry.PossibleValues, true);
                }
            }
            else
            {
                IsDefined = false;
            }
        }
예제 #10
0
        /// <summary>
        /// Visits the field to continue traversing memory tree by object field.
        /// </summary>
        /// <param name="segment">The segment.</param>
        public void VisitField(FieldPathSegment segment)
        {
            FieldLocationVisitor visitor = new FieldLocationVisitor(segment, snapshot.MemoryAssistant, mustLocationProcess, mayLocationProcess);

            visitor.IsMust = true;
            foreach (MemoryIndex index in mustIndexes)
            {
                processField(segment, index, visitor, true);
            }
            foreach (ValueLocation location in mustLocation)
            {
                location.Accept(visitor);
            }

            visitor.IsMust = false;
            foreach (MemoryIndex index in MayIndexes)
            {
                processField(segment, index, visitor, false);
            }
            foreach (ValueLocation location in mayLocation)
            {
                location.Accept(visitor);
            }
        }
예제 #11
0
 public override void CollectField(TreeIndexCollector collector, FieldPathSegment fieldSegment)
 {
     AddNewImplicitObjectNode(true);
     collector.CollectSegmentWithoutStructure(fieldSegment, ImplicitObjectNode, true);
 }
예제 #12
0
 public override void CollectField(TreeIndexCollector collector, FieldPathSegment fieldSegment)
 {
     collectFieldFromMemoryIndex(collector, fieldSegment, sourceMemoryIndex);
 }
예제 #13
0
 /// <summary>
 /// Collects all child nodes by field access.
 /// </summary>
 /// <param name="collector">The collector.</param>
 /// <param name="fieldSegment">The field segment.</param>
 public abstract void CollectField(TreeIndexCollector collector, FieldPathSegment fieldSegment);
예제 #14
0
 /// <summary>
 /// Visits the field.
 /// </summary>
 /// <param name="fieldSegment">The field segment.</param>
 public void VisitField(FieldPathSegment fieldSegment)
 {
     CreatedIndex = snapshot.CreateField(Name, ObjectValue, IsMust, true);
 }
예제 #15
0
        public override void CollectField(TreeIndexCollector collector, FieldPathSegment fieldSegment)
        {
            FieldLocationVisitor visitor = new FieldLocationVisitor(collector, fieldSegment, this);

            ValueLocation.Accept(visitor);
        }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldLocationVisitor"/> class.
 /// </summary>
 /// <param name="fieldSegment">The field segment.</param>
 /// <param name="collector">The collector.</param>
 public FieldLocationVisitor(FieldPathSegment fieldSegment, ReadCollector collector)
     : base(collector.snapshot.MemoryAssistant)
 {
     this.fieldSegment = fieldSegment;
     this.collector    = collector;
 }
예제 #17
0
        /// <summary>
        /// Collects the object.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <param name="objectValue">The object value.</param>
        /// <param name="fieldPathSegment">The field path segment.</param>
        public void CollectObject(TreeIndexCollector collector, ObjectValue objectValue, FieldPathSegment fieldPathSegment)
        {
            ContainerCollectorNode objectNode = GetOrCreateObjectNode(collector, objectValue);

            objectNode.Collect(collector, fieldPathSegment);
        }