// Check if the oneOfConst is complete or not internal override bool VisitTerm(DomainTermExpr expression) { BoolLiteral literal = BoolExpression.GetBoolLiteral(expression); MemberRestriction restriction = literal as MemberRestriction; bool result = restriction == null || restriction.IsComplete == true; return(result); }
private IEnumerable <MemberRestriction> GetConjunctsFromWhereClause(BoolExpression whereClause) { foreach (BoolExpression boolExpr in whereClause.Atoms) { if (boolExpr.IsTrue) { continue; } MemberRestriction result = boolExpr.AsLiteral as MemberRestriction; Debug.Assert(result != null, "Atom must be restriction"); yield return(result); } }
/// <summary> /// See <see cref="BoolLiteral.IsIdentifierEqualTo"/>. Member restriction can be incomplete for this operation. /// </summary> protected override bool IsIdentifierEqualTo(BoolLiteral right) { MemberRestriction rightOneOfConst = right as MemberRestriction; if (rightOneOfConst == null) { return(false); } if (object.ReferenceEquals(this, rightOneOfConst)) { return(true); } return(MemberProjectedSlot.EqualityComparer.Equals(m_restrictedMemberSlot, rightOneOfConst.m_restrictedMemberSlot)); }
/// <summary> /// See <see cref="BoolLiteral.IsEqualTo"/>. Member restriction can be incomplete for this operation. /// </summary> protected override bool IsEqualTo(BoolLiteral right) { MemberRestriction rightRestriction = right as MemberRestriction; if (rightRestriction == null) { return(false); } if (object.ReferenceEquals(this, rightRestriction)) { return(true); } if (false == MemberProjectedSlot.EqualityComparer.Equals(m_restrictedMemberSlot, rightRestriction.m_restrictedMemberSlot)) { return(false); } return(m_domain.IsEqualTo(rightRestriction.m_domain)); }
// requires: The CellConstantDomains in the OneOfConsts of the where // clause are partially done // effects: Given the domains of different variables in domainMap, // fixes the whereClause of this such that all the // CellConstantDomains in OneOfConsts are complete internal void UpdateWhereClause(MemberDomainMap domainMap) { List <BoolExpression> atoms = new List <BoolExpression>(); foreach (BoolExpression atom in WhereClause.Atoms) { BoolLiteral literal = atom.AsLiteral; MemberRestriction restriction = literal as MemberRestriction; Debug.Assert(restriction != null, "All bool literals must be OneOfConst at this point"); // The oneOfConst needs to be fixed with the new possible values from the domainMap. IEnumerable <Constant> possibleValues = domainMap.GetDomain(restriction.RestrictedMemberSlot.MemberPath); MemberRestriction newOneOf = restriction.CreateCompleteMemberRestriction(possibleValues); // Prevent optimization of single constraint e.g: "300 in (300)" // But we want to optimize type constants e.g: "category in (Category)" // To prevent optimization of bool expressions we add a Sentinel OneOF ScalarRestriction scalarConst = restriction as ScalarRestriction; bool addSentinel = scalarConst != null && !scalarConst.Domain.Contains(Constant.Null) && !scalarConst.Domain.Contains(Constant.NotNull) && !scalarConst.Domain.Contains(Constant.Undefined); if (addSentinel) { domainMap.AddSentinel(newOneOf.RestrictedMemberSlot.MemberPath); } atoms.Add(BoolExpression.CreateLiteral(newOneOf, domainMap)); if (addSentinel) { domainMap.RemoveSentinel(newOneOf.RestrictedMemberSlot.MemberPath); } } // We create a new whereClause that has the memberDomainMap set if (atoms.Count > 0) { m_whereClause = BoolExpression.CreateAnd(atoms.ToArray()); } }