private IEnumerable <IEnumerable <XElement> > AddExtraRowTitle( IEnumerable <IEnumerable <XElement> > headderRows, IEnumerable <IEnumerable <XElement> > bodyRows) { if (RowHeaders.Count != 1) { return(headderRows.Concat(bodyRows)); } var headderList = headderRows.AsList(); var bodyList = bodyRows.AsList(); var bodyListCount = bodyList.Count - (HasFooterRow()?1:0); return(PrependFirst(headderList, Elt("Td", "", ("rowspan", headderList.Count))) .Concat(PrependFirst(bodyList, Elt("th", RowHeaders[0].Name, ("rowspan", bodyListCount))))); }
public override bool IsTop(Element /*!*/ element) { //Contract.Requires(element != null); Elt e = (Elt)element; return(!e.IsBottom && e.Count == 0); }
private Elt /*!*/ AddConstraint(Element /*!*/ element, IVariable /*!*/ var, /*MicroLattice*/ Element /*!*/ newValue) { Contract.Requires((newValue != null)); Contract.Requires((var != null)); Contract.Requires((element != null)); Contract.Ensures(Contract.Result <Elt>() != null); Elt e = (Elt)element; if (!e.IsBottom && !this.microLattice.IsBottom(newValue)) // if we're not at bottom { /*MicroLattice*/ Element currentValue = e[var]; if (currentValue == null) { // No information currently, so we just add the new info. return(e.Add(var, newValue, this.microLattice)); } else { // Otherwise, take the meet of the new and current info. //return e.Add(var, this.microLattice.Meet(currentValue, newValue), this.microLattice); return(e.Set(var, this.microLattice.Meet(currentValue, newValue), this.microLattice)); } } return(e); }
public override string /*!*/ ToString(Element /*!*/ element) { //Contract.Requires(element != null); Contract.Ensures(Contract.Result <string>() != null); Elt e = (Elt)element; if (IsTop(e)) { return("<top>"); } if (IsBottom(e)) { return("<bottom>"); } int k = 0; System.Text.StringBuilder buffer = new System.Text.StringBuilder(); foreach (IVariable /*!*/ key in e.SortedVariables(variableComparer)) { Contract.Assert(key != null); if (k++ > 0) { buffer.Append("; "); } buffer.AppendFormat("{0} = {1}", key, e[key]); } return(buffer.ToString()); }
public override Element /*!*/ NontrivialJoin(Element /*!*/ first, Element /*!*/ second) { //Contract.Requires(second != null); //Contract.Requires(first != null); Contract.Ensures(Contract.Result <Element>() != null); Elt a = (Elt)first; Elt b = (Elt)second; IFunctionalMap newMap = FunctionalHashtable.Empty; foreach (IVariable /*!*/ key in a.Variables) { Contract.Assert(key != null); Element aValue = a[key]; Element bValue = b[key]; if (aValue != null && bValue != null) { // Keep only the variables known to both elements. Element newValue = this.microLattice.Join(aValue, bValue); newMap = newMap.Add(key, newValue); } } Elt /*!*/ join = new Elt(newMap); Contract.Assert(join != null); // System.Console.WriteLine("{0} join {1} = {2} ", this.ToString(a), ToString(b), ToString(join)); return(join); }
public override bool IsTop(Element /*!*/ element) { //Contract.Requires(element != null); Elt e = (Elt)element; return(e.domainValue == Value.Top); }
protected override bool AtMost(Element /*!*/ first, ICombineNameMap /*!*/ firstToResult, Element /*!*/ second, ICombineNameMap /*!*/ secondToResult) { //Contract.Requires(secondToResult != null); //Contract.Requires(second != null); //Contract.Requires(firstToResult != null); //Contract.Requires(first != null); Elt a = (Elt)first; Elt b = (Elt)second; for (int i = 0; i < a.Count; i++) { Element thisElement = cce.NonNull(a[i]); Element thatElement = cce.NonNull(b[i]); if (thisElement.GetType() != thatElement.GetType()) { throw new System.InvalidOperationException( "AtMost called on MultiDomain objects with different lattices" ); } if (!SubLattice(i).LowerThan(thisElement, firstToResult, thatElement, secondToResult)) { return(false); } } return(true); }
public override bool IsBottom(Element /*!*/ element) { //Contract.Requires(element != null); Elt e = (Elt)element; return(e.value == Value.Bottom); }
public override bool IsTop(Element /*!*/ element) { //Contract.Requires(element != null); Elt e = (Elt)element; return(e.what == What.Bounds && e.ty == null && e.manyBounds == null); }
public SubelementsEnumerable(MultiLattice /*!*/ multiLattice, Elt /*!*/ multiElement) { Contract.Requires(multiElement != null); Contract.Requires(multiLattice != null); this.multiLattice = multiLattice; this.multiElement = multiElement; // base(); }
public override IExpr GetFoldExpr(Element /*!*/ element) { //Contract.Requires(element != null); Elt e = (Elt)element; Contract.Assert(e.domainValue == Value.Constant); return(factory.Const(e.constantValue)); }
public override string /*!*/ ToString(Element /*!*/ element) { //Contract.Requires(element != null); Contract.Ensures(Contract.Result <string>() != null); Elt e = (Elt)element; return(e.ToString()); }
public SubelementsEnumerator(MultiLattice /*!*/ multiLattice, Elt /*!*/ multiElement) { Contract.Requires(multiElement != null); Contract.Requires(multiLattice != null); Contract.Requires(multiElement.elementPerLattice != null); this.multiLatticeIter = multiLattice.lattices.GetEnumerator(); this.multiElementIter = multiElement.elementPerLattice.GetEnumerator(); // base(); }
protected override bool AtMost(Element /*!*/ first, Element /*!*/ second) // this <= that { //Contract.Requires(first != null); //Contract.Requires(second != null); Elt a = (Elt)first; Elt b = (Elt)second; return(a.value == b.value); }
protected override bool AtMost(Element /*!*/ first, Element /*!*/ second) // this <= that { //Contract.Requires(first!= null); //Contract.Requires(second != null); Elt a = (Elt)first; Elt b = (Elt)second; return(a.Constant.Equals(b.Constant)); }
public override Lattice.Element /*!*/ NontrivialMeet(Element /*!*/ first, Element /*!*/ second) { //Contract.Requires(second != null); //Contract.Requires(first != null); Contract.Ensures(Contract.Result <Lattice.Element>() != null); Elt a = (Elt)first; Elt b = (Elt)second; return((a.value == b.value) ? a : (Elt)Bottom); }
public override int OnElt(CommonElt elt) { if (OnEvent != null) { // Because the event is delivered asynchronously we must copy the elt HERE before the native memory (C++) is destroyed. Elt element = Elt.New(elt); EventHandlerTrigger.TriggerEvent <EltEventArgs>(OnEvent, this, new EltEventArgs(element)); } return(0); }
private Elt(Elt/*!*/ other) { Contract.Requires(other != null); Element[] otherEPL = other.elementPerLattice; if (otherEPL != null) { Element[] newEPL = new Element[otherEPL.Length]; for (int i = 0; i < newEPL.Length; i++) { newEPL[i] = (Element)(cce.NonNull(otherEPL[i])).Clone(); } this.elementPerLattice = newEPL; } }
protected override bool AtMost(Element /*!*/ first, Element /*!*/ second) // this <= that { //Contract.Requires(first != null); //Contract.Requires(second != null); Elt /*!*/ a = (Elt /*!*/)cce.NonNull(first); Elt /*!*/ b = (Elt /*!*/)cce.NonNull(second); Contract.Assert(a.what != What.Bottom && b.what != What.Bottom); if (a.what == What.Exact && b.what == What.Exact) { Contract.Assert(a.ty != null && b.ty != null); return(factory.IsTypeEqual(a.ty, b.ty)); } else if (b.what == What.Exact) { return(false); } else if (a.what == What.Exact) { Contract.Assert(a.ty != null); if (b.ty != null) { return(factory.IsSubType(a.ty, b.ty)); } else { return(Contract.ForAll(b.manyBounds, bound => factory.IsSubType(a.ty, bound))); } } else { Contract.Assert(a.what == What.Bounds && b.what == What.Bounds); Contract.Assert(a.ty != null || a.manyBounds != null); // a precondition is that a is not Top Contract.Assert(b.ty != null || b.manyBounds != null); // a precondition is that b is not Top // Return true iff: for each constraint in b, there is a stricter constraint in a. if (a.ty != null && b.ty != null) { return(factory.IsSubType(a.ty, b.ty)); } else if (a.ty != null) { return(Contract.ForAll(b.manyBounds, bound => factory.IsSubType(a.ty, bound))); } else if (b.ty != null) { return(Contract.Exists(a.manyBounds, bound => factory.IsSubType(bound, b.ty))); } else { return(Contract.ForAll(b.manyBounds, bBound => Contract.Exists(a.manyBounds, aBound => factory.IsSubType(aBound, bBound)))); } } }
public override Element /*!*/ NontrivialMeet(Element /*!*/ first, Element /*!*/ second) { //Contract.Requires(second != null); //Contract.Requires(first != null); Contract.Ensures(Contract.Result <Element>() != null); Elt a = (Elt)first; Elt b = (Elt)second; Debug.Assert(a.domainValue == Value.Constant && b.domainValue == Value.Constant); return((a.constantValue.Equals(b.constantValue)) ? a : (Elt)Bottom); }
void ExplodeMacroblocs(Elt elt) { foreach (Elt _elt in elt.Elements) { if (_elt.Type == Elt.EltType_t.EltType_Mb) { EltMb eltMb = (_elt as EltMb); m_Macroblocs[eltMb.Address] = new Macroblock(Nalu.LayerId, Nalu.PictureId, Nalu.SliceId, eltMb); ExplodeMacroblocs(_elt); } } }
private Elt(Elt /*!*/ other) { Contract.Requires(other != null); Element[] otherEPL = other.elementPerLattice; if (otherEPL != null) { Element[] newEPL = new Element[otherEPL.Length]; for (int i = 0; i < newEPL.Length; i++) { newEPL[i] = (Element)(cce.NonNull(otherEPL[i])).Clone(); } this.elementPerLattice = newEPL; } }
public static Elt /*!*/ Bottom(ArrayList /*<Lattice>*//*!*/ lattices) { Contract.Requires(lattices != null); Contract.Ensures(Contract.Result <Elt>() != null); Elt multiValue = new Elt(lattices.Count, true); for (int i = 0; i < lattices.Count; i++) { Lattice d = (Lattice /*!*/)cce.NonNull(lattices[i]); multiValue[d.Index] = d.Bottom; } Debug.Assert(multiValue.IsValid); return(multiValue); }
public override IExpr GetFoldExpr(Element /*!*/ e) { //Contract.Requires(e != null); Elt elt = (Elt)e; if (elt.value == Value.Null) { return(factory.Null); } else { // can't fold into an expression return(null); } }
public override IExpr /*!*/ ToPredicate(Element /*!*/ element) { //Contract.Requires(element != null); Contract.Ensures(Contract.Result <IExpr>() != null); Elt e = (Elt)element; IExpr result = propExprFactory.True; for (int i = 0; i < e.Count; i++) { IExpr conjunct = SubLattice(i).ToPredicate(cce.NonNull(e[i])); Contract.Assert(conjunct != null); result = Prop.SimplifiedAnd(propExprFactory, conjunct, result); } return(result); }
protected override bool AtMost(Element /*!*/ first, Element /*!*/ second) { //Contract.Requires(second != null); //Contract.Requires(first != null); Elt a = (Elt)first; Elt b = (Elt)second; // return true iff every constraint in "this" is no weaker than the corresponding // constraint in "that" and there are no additional constraints in "that" foreach (IVariable /*!*/ var in a.Variables) { Contract.Assert(var != null); Element thisValue = cce.NonNull(a[var]); Element thatValue = b[var]; if (thatValue == null) { continue; } // it's okay for "a" to know something "b" doesn't if (this.microLattice.LowerThan(thisValue, thatValue)) { continue; } // constraint for "var" satisfies AtMost relation return(false); } foreach (IVariable /*!*/ var in b.Variables) { Contract.Assert(var != null); if (a.Lookup(var) != null) { continue; } // we checked this case in the loop above Element thatValue = cce.NonNull(b[var]); if (this.microLattice.IsTop(thatValue)) { continue; } // this is a trivial constraint return(false); } return(true); }
public override Answer CheckPredicate(Element /*!*/ element, IExpr /*!*/ pred) { //Contract.Requires(pred != null); //Contract.Requires(element != null); Elt /*!*/ e = (Elt /*!*/)cce.NonNull(element); for (int i = 0; i < e.Count; i++) { Answer ans = SubLattice(i).CheckPredicate(cce.NonNull(e[i]), pred); if (ans == Answer.Yes || ans == Answer.No) { return(ans); } } return(Answer.Maybe); }
public override Answer CheckVariableDisequality(Element /*!*/ element, IVariable /*!*/ var1, IVariable /*!*/ var2) { //Contract.Requires(var2 != null); //Contract.Requires(var1 != null); //Contract.Requires(element != null); Elt /*!*/ e = (Elt /*!*/)cce.NonNull(element); for (int i = 0; i < e.Count; i++) { Answer ans = SubLattice(i).CheckVariableDisequality(cce.NonNull(e[i]), var1, var2); if (ans == Answer.Yes || ans == Answer.No) { return(ans); } } return(Answer.Maybe); }
public override Element /*!*/ Eliminate(Element /*!*/ element, IVariable /*!*/ variable) { //Contract.Requires(variable != null); //Contract.Requires(element != null); Contract.Ensures(Contract.Result <Element>() != null); Elt e = (Elt)element; if (IsBottom(e)) { return(e); } Elt newValue = new Elt(e.Count, false); for (int i = 0; i < this.lattices.Count; i++) { newValue[i] = SubLattice(i).Eliminate(cce.NonNull(e[i]), variable); } return(newValue); }
public override Element /*!*/ Constrain(Element /*!*/ element, IExpr /*!*/ expr) { //Contract.Requires(expr != null); //Contract.Requires(element != null); //Contract.Ensures(Contract.Result<Element>() != null); Elt e = (Elt)element; if (IsBottom(e)) { return(e); } Elt newValue = new Elt(e.Count, false); for (int i = 0; i < this.lattices.Count; i++) { newValue[i] = SubLattice(i).Constrain(cce.NonNull(e[i]), expr); } return(newValue); }
public override bool IsBottom(Element /*!*/ element) { //Contract.Requires(element != null); Elt e = (Elt)element; // The program is errorneous/nonterminating if any subdomain knows it is. // if (e.elementPerLattice == null) { return(true); } for (int i = 0; i < e.Count; i++) { if (SubLattice(i).IsBottom(cce.NonNull(e[i]))) { return(true); } } return(false); }
/// <summary> /// Perform the pointwise widening of the elements in the map /// </summary> public override Element/*!*/ Widen(Element/*!*/ first, Element/*!*/ second) { //Contract.Requires((second != null)); //Contract.Requires((first != null)); Contract.Ensures(Contract.Result<Element>() != null); Elt a = (Elt)first; Elt b = (Elt)second; // Note we have to add those cases as we do not have a "NonTrivialWiden" method if (a.IsBottom) return new Elt(b.Constraints); if (b.IsBottom) return new Elt(a.Constraints); IFunctionalMap newMap = FunctionalHashtable.Empty; foreach (IVariable/*!*/ key in a.Variables) { Contract.Assert(key != null); Element aValue = a[key]; Element bValue = b[key]; if (aValue != null && bValue != null) { // Keep only the variables known to both elements. Element newValue = this.microLattice.Widen(aValue, bValue); newMap = newMap.Add(key, newValue); } } Element/*!*/ widen = new Elt(newMap); Contract.Assert(widen != null); // System.Console.WriteLine("{0} widen {1} = {2} ", this.ToString(a), ToString(b), ToString(widen)); return widen; }
public SubelementsEnumerable(MultiLattice/*!*/ multiLattice, Elt/*!*/ multiElement) { Contract.Requires(multiElement != null); Contract.Requires(multiLattice != null); this.multiLattice = multiLattice; this.multiElement = multiElement; // base(); }
public SubelementsEnumerator(MultiLattice/*!*/ multiLattice, Elt/*!*/ multiElement) { Contract.Requires(multiElement != null); Contract.Requires(multiLattice != null); Contract.Requires(multiElement.elementPerLattice != null); this.multiLatticeIter = multiLattice.lattices.GetEnumerator(); this.multiElementIter = multiElement.elementPerLattice.GetEnumerator(); // base(); }
public override Element/*!*/ Rename(Element/*!*/ element, IVariable/*!*/ oldName, IVariable/*!*/ newName) { //Contract.Requires(newName != null); //Contract.Requires(oldName != null); //Contract.Requires(element != null); Contract.Ensures(Contract.Result<Element>() != null); Elt e = (Elt)element; if (IsBottom(e)) { return e; } Elt newValue = new Elt(e.Count, false); for (int i = 0; i < this.lattices.Count; i++) { newValue[i] = SubLattice(i).Rename(cce.NonNull(e[i]), oldName, newName); } return newValue; }
public EltEventArgs(Elt elt) : base() { m_Elt = elt; }
public override Element/*!*/ Constrain(Element/*!*/ element, IExpr/*!*/ expr) { //Contract.Requires(expr != null); //Contract.Requires(element != null); //Contract.Ensures(Contract.Result<Element>() != null); Elt e = (Elt)element; if (IsBottom(e)) { return e; } Elt newValue = new Elt(e.Count, false); for (int i = 0; i < this.lattices.Count; i++) { newValue[i] = SubLattice(i).Constrain(cce.NonNull(e[i]), expr); } return newValue; }
private Element/*!*/ Combine(Element/*!*/ first, ICombineNameMap/*?*/ firstToResult, Element/*!*/ second, ICombineNameMap/*?*/ secondToResult, CombineOp c) { Contract.Requires(second != null); Contract.Requires(first != null); Contract.Ensures(Contract.Result<Element>() != null); Elt a = (Elt)first; Elt b = (Elt)second; int unionCount = System.Math.Max(a.Count, b.Count); Elt combined = new Elt(unionCount, IsBottom(a) && IsBottom(b)); for (int i = 0; i < unionCount; i++) { bool thisExists = a.Contains(i); bool thatExists = b.Contains(i); if (thisExists && thatExists) { Lattice.Element suba = a[i]; Lattice.Element subb = b[i]; Contract.Assert(suba != null && subb != null); switch (c) { case CombineOp.Meet: combined[i] = SubLattice(i).Meet(suba, subb); break; case CombineOp.Join: if (firstToResult != null && secondToResult != null) combined[i] = SubLattice(i).Join(suba, firstToResult, subb, secondToResult); else combined[i] = SubLattice(i).Join(suba, subb); break; case CombineOp.Widen: if (firstToResult != null && secondToResult != null) combined[i] = SubLattice(i).Widen(suba, firstToResult, subb, secondToResult); else combined[i] = SubLattice(i).Widen(suba, subb); break; } } else if (thisExists) { combined[i] = a[i]; } else { combined[i] = b[i]; } } Debug.Assert(combined.IsValid); return combined; }
public override Element/*!*/ NontrivialJoin(Element/*!*/ first, Element/*!*/ second) { //Contract.Requires(second != null); //Contract.Requires(first != null); Contract.Ensures(Contract.Result<Element>() != null); Elt a = (Elt)first; Elt b = (Elt)second; IFunctionalMap newMap = FunctionalHashtable.Empty; foreach (IVariable/*!*/ key in a.Variables) { Contract.Assert(key != null); Element aValue = a[key]; Element bValue = b[key]; if (aValue != null && bValue != null) { // Keep only the variables known to both elements. Element newValue = this.microLattice.Join(aValue, bValue); newMap = newMap.Add(key, newValue); } } Elt/*!*/ join = new Elt(newMap); Contract.Assert(join != null); // System.Console.WriteLine("{0} join {1} = {2} ", this.ToString(a), ToString(b), ToString(join)); return join; }
void ShowH264Headers(Elt[] ppsElts, Elt[] spsElts, Elt[] sliceElts) { if (m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_PPS] == null) { m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_PPS] = new ScreenHeader(ppsElts); ScreenBase.AddToTabControl(m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_PPS], tabControlHdrs); } else { m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_PPS].Elts = ppsElts; } if (m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SPS] == null) { m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SPS] = new ScreenHeader(spsElts); ScreenBase.AddToTabControl(m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SPS], tabControlHdrs); } else { m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SPS].Elts = spsElts; } if (m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SliceHeader] == null) { m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SliceHeader] = new ScreenHeader(sliceElts); ScreenBase.AddToTabControl(m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SliceHeader], tabControlHdrs); } else { m_ScreenHeaders[(int)H264HeaderEltType_t.H264HeaderEltType_SliceHeader].Elts = sliceElts; } }
/// <summary> /// Return a new expression in which each variable has been /// replaced by an expression representing what is known about /// that variable. /// </summary> private IExpr/*!*/ InlineVariables(Elt/*!*/ element, IExpr/*!*/ expr, ISet/*<IVariable!>*//*!*/ notInlineable, OnUnableToInline/*!*/ unableToInline) { Contract.Requires(unableToInline != null); Contract.Requires(notInlineable != null); Contract.Requires(expr != null); Contract.Requires(element != null); Contract.Ensures(Contract.Result<IExpr>() != null); IVariable var = expr as IVariable; if (var != null) { /*MicroLattice*/ Element value = element[var]; if (notInlineable.Contains(var) || value == null || this.microLattice.IsTop(value)) { return unableToInline(var); // We don't know anything about this variable. } else { // GetFoldExpr returns null when it can yield an expression that // can be substituted for the variable. IExpr valueExpr = this.microLattice.GetFoldExpr(value); return (valueExpr == null) ? var : valueExpr; } } // else IFunApp fun = expr as IFunApp; if (fun != null) { IList newargs = new ArrayList(); foreach (IExpr/*!*/ arg in fun.Arguments) { Contract.Assert(arg != null); newargs.Add(InlineVariables(element, arg, notInlineable, unableToInline)); } return fun.CloneWithArguments(newargs); } // else IFunction lambda = expr as IFunction; if (lambda != null) { IMutableSet x = new HashSet(1); x.Add(lambda.Param); // Don't inline the bound variable return lambda.CloneWithBody( InlineVariables(element, lambda.Body, cce.NonNull(Set.Union(notInlineable, x)), unableToInline) ); } // else if (expr is IUnknown) { return expr; } else { throw new System.NotImplementedException("cannot inline identifies in expression " + expr); } }
public static Elt/*!*/ Top(ArrayList/*<Lattice>*//*!*/ lattices) { Contract.Requires(lattices != null); Contract.Ensures(Contract.Result<Elt>() != null); Elt multiValue = new Elt(lattices.Count, false); for (int i = 0; i < lattices.Count; i++) { Lattice d = (Lattice/*!*/)cce.NonNull(lattices[i]); multiValue[d.Index] = d.Top; } Debug.Assert(multiValue.IsValid); return multiValue; }