Ejemplo n.º 1
0
		public override PathCond Or(PathCond other) {
			if (other is CachedAtom && conds.Contains(((CachedAtom)other).Negate())) {
				// Reduce Or(OR(...,e,...), NOT(e)) and Or(OR(...,NOT(e),...), e) to TRUE
				return TRUE;
			}
			else if (other is Disj) {
				HashList<PathCond> result = new HashList<PathCond>();
				result.AddAll(conds);
				foreach (PathCond cond in ((Disj)other).conds) {
					if (cond is CachedAtom && conds.Contains((cond as CachedAtom).Negate())) {
						// Reduce Or(OR(...,e,...),OR(...,NOT(e),...)) to TRUE
						// and    Or(OR(...,NOT(e),...),OR(...,e,...)) to TRUE
						return TRUE;
					}
					result.Add(cond);
				}
				return Disj.Make(result.ToArray());
			}
			else if (other is Conj) {
				if (((Conj)other).conds.Contains(this)) {
					// Reduce (pi | (p1 & ... & pn)) to pi
					return this;
				}
				else {
					if (((Conj)other).conds.Any(cond => conds.Contains(cond))) {
						return this;
					}
				}
				return Disj.Make(AddItem(this.conds, other));
			}
			else {
				return Disj.Make(AddItem(this.conds, other));
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Build a list of all the Formula and ArrayFormula cells that the outputCell
        /// depends on, in calculation order.
        /// </summary>
        /// <returns>Cells sorted in calculation order; output cell last.</returns>
        public IList <FullCellAddr> PrecedentOrder()
        {
            HashList <FullCellAddr> sorted = new HashList <FullCellAddr>();

            AddNode(sorted, outputCell);
            return(sorted.ToArray());
        }
Ejemplo n.º 3
0
        public static PathCond Make(params PathCond[] conjs)
        {
            HashList <PathCond> result = new HashList <PathCond>();

            foreach (PathCond conj in conjs)
            {
                if (conj.Is(false))
                {
                    return(FALSE);
                }
                else if (!conj.Is(true))
                {
                    result.Add(conj);
                }
            }
            if (result.Count == 0)
            {
                return(TRUE);
            }
            else if (result.Count == 1)
            {
                return(result.Single());
            }
            else
            {
                return(new Conj(result.ToArray()));
            }
        }
Ejemplo n.º 4
0
        public override PathCond Or(PathCond other)
        {
            if (this.Is(true) || other.Is(true))
            {
                return(TRUE);
            }
            else if (this.Is(false))
            {
                return(other);
            }
            else if (other.Is(false))
            {
                return(this);
            }
            else if (conds.Contains(other))
            {
                // Reduce ((p1 & ... & pn)) | pi to pi
                return(other);
            }
            else if (other is Disj)
            {
                // TODO: This doesn't preserve order of disjuncts:
                return(other.Or(this));
            }
            else if (other is Conj)
            {
                if ((other as Conj).conds.Contains(this))
                {
                    // Reduce (pi | (p1 & ... & pn)) to pi
                    return(this);
                }
                else
                {
                    HashList <PathCond> intersect = HashList <PathCond> .Intersection(this.conds, (other as Conj).conds);

                    if (intersect.Count > 0)
                    {
                        // Reduce (p1 & ... & pn & q1 & ... & qm) | (p1 & ... & pn & r1 & ... & rk)
                        // to (p1 & ... & pn & (q1 & ... & qm | r1 & ... & rk).
                        // The pi go in intersect, qi in thisRest, and ri in otherRest.
                        HashList <PathCond> thisRest = HashList <PathCond> .Difference(this.conds, intersect);

                        HashList <PathCond> otherRest = HashList <PathCond> .Difference((other as Conj).conds, intersect);

                        // This recursion terminates because thisRest is smaller than this.conds
                        intersect.Add(Conj.Make(thisRest.ToArray()).Or(Conj.Make(otherRest.ToArray())));
                        return(Conj.Make(intersect.ToArray()));
                    }
                    else
                    {
                        return(Disj.Make(AddItem(this.conds, other)));
                    }
                }
            }
            else
            {
                return(Disj.Make(this, other));
            }
        }
Ejemplo n.º 5
0
        protected static PathCond[] AddItem(IEnumerable <PathCond> set, PathCond item)
        {
            HashList <PathCond> result = new HashList <PathCond>();

            result.AddAll(set);
            result.Add(item);
            return(result.ToArray());
        }
Ejemplo n.º 6
0
        public void ToArrayTest()
        {
            var copiedContents = _list1.ToArray();

            Assert.IsFalse(ReferenceEquals(copiedContents, _list1_contents));

            Assert.AreEqual(_list1.Count, copiedContents.Length);
            Assert.AreEqual(_list1[0], copiedContents[0]);
        }
        internal void BuildFunctionPointers()
        {
            _signatures = _methodRefs.ToArray();
            _methodRefs = null;

            _dataOffset = _resourceStorage.Size;

            var resourceBlob = _resourceStorage.Blob;
            int offset       = resourceBlob.Length;
            int size         = _signatures.Length * 4;

            resourceBlob.Allocate(offset, size);
            _blob = new Blob(resourceBlob.GetBuffer(), offset, size, true);

            Generate();
        }
Ejemplo n.º 8
0
 public override PathCond Or(PathCond other)
 {
     if (other is CachedAtom && conds.Contains(((CachedAtom)other).Negate()))
     {
         // Reduce Or(OR(...,e,...), NOT(e)) and Or(OR(...,NOT(e),...), e) to TRUE
         return(TRUE);
     }
     else if (other is Disj)
     {
         HashList <PathCond> result = new HashList <PathCond>();
         result.AddAll(conds);
         foreach (PathCond cond in ((Disj)other).conds)
         {
             if (cond is CachedAtom && conds.Contains((cond as CachedAtom).Negate()))
             {
                 // Reduce Or(OR(...,e,...),OR(...,NOT(e),...)) to TRUE
                 // and    Or(OR(...,NOT(e),...),OR(...,e,...)) to TRUE
                 return(TRUE);
             }
             result.Add(cond);
         }
         return(Disj.Make(result.ToArray()));
     }
     else if (other is Conj)
     {
         if (((Conj)other).conds.Contains(this))
         {
             // Reduce (pi | (p1 & ... & pn)) to pi
             return(this);
         }
         else
         {
             if (((Conj)other).conds.Any(cond => conds.Contains(cond)))
             {
                 return(this);
             }
         }
         return(Disj.Make(AddItem(this.conds, other)));
     }
     else
     {
         return(Disj.Make(AddItem(this.conds, other)));
     }
 }
Ejemplo n.º 9
0
		public static PathCond Make(params PathCond[] conjs) {
			HashList<PathCond> result = new HashList<PathCond>();
			foreach (PathCond conj in conjs) {
				if (conj.Is(false)) {
					return FALSE;
				}
				else if (!conj.Is(true)) {
					result.Add(conj);
				}
			}
			if (result.Count == 0) {
				return TRUE;
			}
			else if (result.Count == 1) {
				return result.Single();
			}
			else {
				return new Conj(result.ToArray());
			}
		}
Ejemplo n.º 10
0
		/// <summary>
		/// Build a list of all the Formula and ArrayFormula cells that the outputCell 
		/// depends on, in calculation order.
		/// </summary>
		/// <returns>Cells sorted in calculation order; output cell last.</returns>
		public IList<FullCellAddr> PrecedentOrder() {
			HashList<FullCellAddr> sorted = new HashList<FullCellAddr>();
			AddNode(sorted, outputCell);
			return sorted.ToArray();
		}
Ejemplo n.º 11
0
 public int[] ToArray()
 {
     return(_list.ToArray());
 }