Exemple #1
0
            // The real work happens here in the literal's RemapBool
            internal override DomainBoolExpr VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral literal    = BoolExpression.GetBoolLiteral(expression);
                BoolLiteral newLiteral = literal.RemapBool(m_remap);

                return(newLiteral.GetDomainBoolExpression(m_memberDomainMap));
            }
Exemple #2
0
            // The real work happens here in the literal's FixRange
            internal override DomainBoolExpr VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral    literal = BoolExpression.GetBoolLiteral(expression);
                DomainBoolExpr result  = literal.FixRange(expression.Identifier.Range, m_memberDomainMap);

                return(result);
            }
Exemple #3
0
        /// <summary>
        /// Creates a term expression of the form: "<paramref name="literal"/> in <paramref name="range"/> with all possible values being <paramref name="domain"/>".
        /// </summary>
        internal static DomainTermExpr MakeTermExpression(BoolLiteral literal, IEnumerable <Constant> domain, IEnumerable <Constant> range)
        {
            Set <Constant> domainSet = new Set <Constant>(domain, Constant.EqualityComparer);
            Set <Constant> rangeSet  = new Set <Constant>(range, Constant.EqualityComparer);

            return(MakeTermExpression(literal, domainSet, rangeSet));
        }
Exemple #4
0
            internal override StringBuilder VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                literal.ToCompactString(m_builder);
                return(m_builder);
            }
Exemple #5
0
            // The real work happends here - the slots are obtained from the literal
            internal override DomainBoolExpr VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                literal.GetRequiredSlots(m_projectedSlotMap, m_requiredSlots);
                return(expression);
            }
Exemple #6
0
            // 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);
            }
Exemple #7
0
            internal override T_Return VisitTerm(DomainTermExpr expression)
            {
                // If m_skipIsNotNull is true at this point, it means that no ancestor of this
                // node is OR or NOT
                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                return(BooleanLiteralAsCql(literal, m_skipIsNotNull));
            }
        protected override bool IsEqualTo(BoolLiteral right)
        {
            CellIdBoolean rightBoolean = right as CellIdBoolean;

            if (rightBoolean == null)
            {
                return(false);
            }
            return(m_index == rightBoolean.m_index);
        }
        protected override bool IsEqualTo(BoolLiteral right)
        {
            RoleBoolean rightBoolean = right as RoleBoolean;

            if (rightBoolean == null)
            {
                return(false);
            }
            return(m_metadataItem == rightBoolean.m_metadataItem);
        }
Exemple #10
0
        /// <summary>
        /// Creates a term expression of the form: "<paramref name="literal"/> in <paramref name="range"/> with all possible values being <paramref name="domain"/>".
        /// </summary>
        internal static DomainTermExpr MakeTermExpression(BoolLiteral literal, Set <Constant> domain, Set <Constant> range)
        {
            domain.MakeReadOnly();
            range.MakeReadOnly();

            DomainVariable   variable   = new DomainVariable(literal, domain, EqualityIdentifierComparer);
            DomainConstraint constraint = new DomainConstraint(variable, range);
            DomainTermExpr   result     = new DomainTermExpr(EqualityComparer <DomainConstraint> .Default, constraint);

            return(result);
        }
Exemple #11
0
            internal override StringBuilder VisitTerm(DomainTermExpr expression)
            {
                // If m_skipIsNotNull is true at this point, it means that no ancestor of this
                // node is OR or NOT

                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                if (literal is ScalarRestriction || literal is TypeRestriction)
                {
                    return(literal.AsUserString(m_builder, Strings.ViewGen_EntityInstanceToken, m_skipIsNotNull));
                }

                return(literal.AsUserString(m_builder, m_blockAlias, m_skipIsNotNull));
            }
Exemple #12
0
        /// <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));
        }
Exemple #13
0
        /// <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));
        }
Exemple #14
0
        // 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());
            }
        }
Exemple #15
0
            internal override StringBuilder VisitNot(DomainNotExpr expression)
            {
                m_skipIsNotNull = false; // Cannot skip in NOTs

                DomainTermExpr termExpr = expression.Child as DomainTermExpr;

                if (termExpr != null)
                {
                    BoolLiteral literal = BoolExpression.GetBoolLiteral(termExpr);
                    return(literal.AsNegatedUserString(m_builder, m_blockAlias, m_skipIsNotNull));
                }
                else
                {
                    m_builder.Append("NOT(");
                    // We do not need the returned StringBuilder -- it is the same as m_builder
                    expression.Child.Accept(this);
                    m_builder.Append(")");
                }
                return(m_builder);
            }
Exemple #16
0
 /// <summary>
 /// Checks if the identifier in this is the same as the one in <paramref name="right"/>.
 /// </summary>
 protected virtual bool IsIdentifierEqualTo(BoolLiteral right)
 {
     return(IsEqualTo(right));
 }
Exemple #17
0
 protected abstract T_Return BooleanLiteralAsCql(BoolLiteral literal, bool skipIsNotNull);
Exemple #18
0
 protected override DbExpression BooleanLiteralAsCql(BoolLiteral literal, bool skipIsNotNull)
 {
     return(literal.AsCqt(m_row, skipIsNotNull));
 }
Exemple #19
0
        // effects: Create a boolean expression from a literal value
        internal static BoolExpression CreateLiteral(BoolLiteral literal, MemberDomainMap memberDomainMap)
        {
            DomainBoolExpr expr = literal.GetDomainBoolExpression(memberDomainMap);

            return(new BoolExpression(expr, memberDomainMap));
        }
Exemple #20
0
 protected abstract bool IsEqualTo(BoolLiteral right);
Exemple #21
0
        // effects: Creates a new boolean expression using the memberDomainMap of this expression
        internal BoolExpression Create(BoolLiteral literal)
        {
            DomainBoolExpr expr = literal.GetDomainBoolExpression(m_memberDomainMap);

            return(new BoolExpression(expr, m_memberDomainMap));
        }
Exemple #22
0
 protected override StringBuilder BooleanLiteralAsCql(BoolLiteral literal, bool skipIsNotNull)
 {
     return(literal.AsEsql(m_builder, m_blockAlias, skipIsNotNull));
 }