예제 #1
0
파일: CoolRule.cs 프로젝트: NadavPoraz/CuLe
        public SetOperatorCuLeRule(CuLeSet i_SetA, CuLeSet i_SetB, SetOperator i_SetOperator, string i_state)
        {
            m_SetA        = i_SetA;
            m_SetB        = i_SetB;
            m_SetOperator = i_SetOperator;

            m_state = i_state;
        }
예제 #2
0
파일: CoolRule.cs 프로젝트: NadavPoraz/CuLe
        }// End of Create CuLeRule

        public SetOperatorCuLeRule CreateSetOperatorCuLeRule(CuLeSet i_SetA, CuLeSet i_SetB, SetOperator i_setOperator, SourceLocation i_sourceLocation, string i_state)
        {
            ElementsCuLeSetType lv_ElementsCuLeSetTypeA;
            ElementsCuLeSetType lv_ElementsCuLeSetTypeB;



            switch (i_setOperator)
            {
            case SetOperator.IsSubsetOf:

                if (i_SetA.CuLeSetType.GetSignatureType == CuLeSetType.SignatureType.emptySet)
                {
                    return(new SetOperatorCuLeRule(i_SetA, i_SetB, i_setOperator, i_state));
                }

                if (i_SetA.CuLeSetType.GetSignatureType != i_SetB.CuLeSetType.GetSignatureType)
                {
                    m_errorMessages.Add(new ErrorMessage("Set of type " + i_SetA.CuLeSetType.GetSignatureType + " cannot be a Subset of a set of type " + i_SetB.CuLeSetType.GetSignatureType, i_sourceLocation));
                    return(null);
                }

                if (!(i_SetA.CuLeSetType is ElementsCuLeSetType && i_SetB.CuLeSetType is ElementsCuLeSetType))
                {
                    m_errorMessages.Add(new ErrorMessage("Set of type " + i_SetA.CuLeSetType.GetSignatureType + " cannot be a Subset of a set of type " + i_SetB.CuLeSetType.GetSignatureType, i_sourceLocation));
                    return(null);
                }

                lv_ElementsCuLeSetTypeA = (ElementsCuLeSetType)i_SetA.CuLeSetType;
                lv_ElementsCuLeSetTypeB = (ElementsCuLeSetType)i_SetB.CuLeSetType;

                if (lv_ElementsCuLeSetTypeA.SignatureName != lv_ElementsCuLeSetTypeB.SignatureName)
                {
                    m_errorMessages.Add(new ErrorMessage("Set of type " + lv_ElementsCuLeSetTypeA.SignatureName + " cannot be a Subset of a set of type " + lv_ElementsCuLeSetTypeB.SignatureName, i_sourceLocation));
                    return(null);
                }

                if (lv_ElementsCuLeSetTypeA.GetMultiplicity == CuLeSetType.Multiplicity.many && lv_ElementsCuLeSetTypeA.GetMultiplicity == CuLeSetType.Multiplicity.single)
                {
                    m_errorMessages.Add(new ErrorMessage("Set of multiple elements cannot be a assigned as a Subset of a single element", i_sourceLocation));
                    return(null);
                }

                return(new SetOperatorCuLeRule(i_SetA, i_SetB, i_setOperator, i_state));

            case SetOperator.EQ:
            case SetOperator.NE:


                if (i_SetA.CuLeSetType.GetSignatureType != i_SetB.CuLeSetType.GetSignatureType)
                {
                    if (i_SetA.CuLeSetType.GetSignatureType != CuLeSetType.SignatureType.emptySet && i_SetB.CuLeSetType.GetSignatureType != CuLeSetType.SignatureType.emptySet)
                    {
                        m_errorMessages.Add(new ErrorMessage("Set of type " + i_SetA.CuLeSetType.GetSignatureType + " cannot be a compared to a set of type " + i_SetB.CuLeSetType.GetSignatureType, i_sourceLocation));
                        return(null);
                    }
                }

                if (i_SetA.CuLeSetType is ElementsCuLeSetType && i_SetB.CuLeSetType is ElementsCuLeSetType)
                {
                    lv_ElementsCuLeSetTypeA = (ElementsCuLeSetType)i_SetA.CuLeSetType;
                    lv_ElementsCuLeSetTypeB = (ElementsCuLeSetType)i_SetB.CuLeSetType;


                    if (lv_ElementsCuLeSetTypeA.GetMultiplicity != lv_ElementsCuLeSetTypeA.GetMultiplicity)
                    {
                        m_errorMessages.Add(new ErrorMessage("Set of multiple elements cannot be compared to a single element", i_sourceLocation));
                        return(null);
                    }

                    if (lv_ElementsCuLeSetTypeA.SignatureName != lv_ElementsCuLeSetTypeB.SignatureName)
                    {
                        m_errorMessages.Add(new ErrorMessage("Set of type " + lv_ElementsCuLeSetTypeA.SignatureName + " cannot be compared to a set of type " + lv_ElementsCuLeSetTypeB.SignatureName, i_sourceLocation));
                        return(null);
                    }

                    if (i_SetA.CuLeSetType is FieldCuLeSetType && i_SetB.CuLeSetType is FieldCuLeSetType)
                    {
                        SingleFieldCuLeSetType lv_FieldCuLeSetTypeA = (SingleFieldCuLeSetType)i_SetA.CuLeSetType;
                        SingleFieldCuLeSetType lv_FieldCuLeSetTypeB = (SingleFieldCuLeSetType)i_SetB.CuLeSetType;

                        if (lv_FieldCuLeSetTypeA.FieldType != lv_FieldCuLeSetTypeB.FieldType)
                        {
                            m_errorMessages.Add(new ErrorMessage("Set of type " + lv_FieldCuLeSetTypeA.FieldType.Name + " cannot be compared to a Set of type " + lv_FieldCuLeSetTypeB.FieldType.Name, i_sourceLocation));
                            return(null);
                        }

                        if (lv_FieldCuLeSetTypeA.FieldCaption != lv_FieldCuLeSetTypeB.FieldCaption)
                        {
                            m_errorMessages.Add(new ErrorMessage("Set of type " + lv_FieldCuLeSetTypeA.FieldCaption + " cannot be compared to a set of type " + lv_FieldCuLeSetTypeB.FieldCaption, i_sourceLocation));
                            return(null);
                        }
                    }
                }

                return(new SetOperatorCuLeRule(i_SetA, i_SetB, i_setOperator, i_state));


            case SetOperator.GE:
            case SetOperator.GT:
            case SetOperator.SE:
            case SetOperator.ST:


                if (!(i_SetA.CuLeSetType is ElementsCuLeSetType && i_SetB.CuLeSetType is ElementsCuLeSetType))
                {
                    m_errorMessages.Add(new ErrorMessage("Set of type " + i_SetA.CuLeSetType.GetSignatureType + " cannot be compared to a Set of type " + i_SetA.CuLeSetType.GetSignatureType, i_sourceLocation));
                    return(null);
                }

                lv_ElementsCuLeSetTypeA = (ElementsCuLeSetType)i_SetA.CuLeSetType;
                lv_ElementsCuLeSetTypeB = (ElementsCuLeSetType)i_SetB.CuLeSetType;

                if (lv_ElementsCuLeSetTypeA.SignatureName != lv_ElementsCuLeSetTypeB.SignatureName)
                {
                    m_errorMessages.Add(new ErrorMessage("Set of type " + lv_ElementsCuLeSetTypeA.SignatureName + " cannot be compared to a set of type " + lv_ElementsCuLeSetTypeB.SignatureName, i_sourceLocation));
                    return(null);
                }

                if (lv_ElementsCuLeSetTypeA.GetMultiplicity == CuLeSetType.Multiplicity.many || lv_ElementsCuLeSetTypeA.GetMultiplicity == CuLeSetType.Multiplicity.many)
                {
                    m_errorMessages.Add(new ErrorMessage("Cannot compare set of multiple elements", i_sourceLocation));
                    return(null);
                }

                if (!(i_SetA.CuLeSetType is FieldCuLeSetType && i_SetA.CuLeSetType is FieldCuLeSetType))
                {
                    m_errorMessages.Add(new ErrorMessage("Ordered Set comparison can only be applied to single value elements ", i_sourceLocation));
                    return(null);
                }

                if (!(i_SetA.CuLeSetType is SingleFieldCuLeSetType && i_SetA.CuLeSetType is SingleFieldCuLeSetType))
                {
                    m_errorMessages.Add(new ErrorMessage("Ordered Set comparison cannot be applied to sets of multiple elements", i_sourceLocation));
                    return(null);
                }

                SingleFieldCuLeSetType lv_SingleFieldCuLeSetTypeA = (SingleFieldCuLeSetType)i_SetA.CuLeSetType;
                SingleFieldCuLeSetType lv_SingleFieldCuLeSetTypeB = (SingleFieldCuLeSetType)i_SetB.CuLeSetType;

                if (lv_SingleFieldCuLeSetTypeA.FieldType != lv_SingleFieldCuLeSetTypeB.FieldType)
                {
                    m_errorMessages.Add(new ErrorMessage("Ordered Set comparison cannot be applied to element of type " + lv_SingleFieldCuLeSetTypeA.FieldType.Name + " and element of type " + lv_SingleFieldCuLeSetTypeB.FieldType.Name, i_sourceLocation));
                    return(null);
                }

                if (lv_SingleFieldCuLeSetTypeA.FieldCaption != lv_SingleFieldCuLeSetTypeB.FieldCaption)
                {
                    m_errorMessages.Add(new ErrorMessage("Ordered Set comparison cannot be applied to element of type " + lv_SingleFieldCuLeSetTypeA.FieldCaption + " and element of type " + lv_SingleFieldCuLeSetTypeB.FieldCaption, i_sourceLocation));
                    return(null);
                }

                switch (lv_SingleFieldCuLeSetTypeA.FieldType.FullName)
                {
                case "System.DateTime":
                case "System.Decimal":
                case "System.Double":
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":

                    return(new SetOperatorCuLeRule(i_SetA, i_SetB, i_setOperator, i_state));

                default:

                    m_errorMessages.Add(new ErrorMessage("Ordered Set comparison cannot be applied to elements of type " + lv_SingleFieldCuLeSetTypeA.FieldType.FullName, i_sourceLocation));
                    return(null);
                }
            }

            return(null);
        }
예제 #3
0
파일: CoolRule.cs 프로젝트: NadavPoraz/CuLe
        public CuLeRule CreateCuLeRule(CuLeRuleDef i_CuLeRuleDef, CuLeQuantifierList i_CuLeQuantifierList, string i_State)
        {
            if (i_CuLeRuleDef is SetOperatorCuLeRuleDef)
            {
                SetOperatorCuLeRuleDef l_SetOperatorCuLeRuleDef = (SetOperatorCuLeRuleDef)i_CuLeRuleDef;

                CuLeSetFactory l_CuLeSetFactory = new CuLeSetFactory(m_Tables, m_Relations, this.m_States);

                CuLeSet SetA = l_CuLeSetFactory.CreateCuLeSet(l_SetOperatorCuLeRuleDef.SetDefA(), i_CuLeQuantifierList, i_State);
                CuLeSet SetB = l_CuLeSetFactory.CreateCuLeSet(l_SetOperatorCuLeRuleDef.SetDefB(), i_CuLeQuantifierList, i_State);

                if (l_CuLeSetFactory.m_errorMessages != null)
                {
                    if (l_CuLeSetFactory.m_errorMessages.Count != 0)
                    {
                        this.m_errorMessages = l_CuLeSetFactory.m_errorMessages;
                    }
                }

                if (SetA != null && SetB != null)
                {
                    return(CreateSetOperatorCuLeRule(SetA, SetB, l_SetOperatorCuLeRuleDef.SetOperator, l_SetOperatorCuLeRuleDef.SourceLocation, i_State));
                }

                if (this.m_errorMessages != null)
                {
                    return(null);
                }

                return(null);
            }

            if (i_CuLeRuleDef is NegationCuLeRuleDef)
            {
                NegationCuLeRuleDef l_NegationCuLeRuleDef = (NegationCuLeRuleDef)i_CuLeRuleDef;

                CuLeRule l_CuLeRule_A = this.CreateCuLeRule(l_NegationCuLeRuleDef.CuLeRuleDef_A(), i_CuLeQuantifierList, i_State);

                return(new NegationCuLeRule(l_CuLeRule_A));

                // CuLeRule l_CuLeRule = this.CreateCuLeRule(l_NegationCuLeRuleDef.CuLeRuleDef_A, i_Tables, i_Relations, i_CuLeQuantifierList)
            }

            if (i_CuLeRuleDef is RuleOperatorCuLeRuleDef)
            {
                RuleOperatorCuLeRuleDef l_RuleOperatorCuLeRuleDef = (RuleOperatorCuLeRuleDef)i_CuLeRuleDef;

                CuLeRule l_CuLeRule_A = this.CreateCuLeRule(l_RuleOperatorCuLeRuleDef.CuLeRuleDef_A(), i_CuLeQuantifierList, i_State);
                CuLeRule l_CuLeRule_B = this.CreateCuLeRule(l_RuleOperatorCuLeRuleDef.CuLeRuleDef_B(), i_CuLeQuantifierList, i_State);

                return(new RuleOperatorCuLeRule(l_CuLeRule_A, l_CuLeRule_B, l_RuleOperatorCuLeRuleDef.RuleOperator));
            }

            if (i_CuLeRuleDef is ConditionalCuLeRuleDef)
            {
                if (i_CuLeRuleDef is ImplicationCuLeRuleDef)
                {
                    if (i_CuLeRuleDef is IF_ImplicationCuLeRuleDef)
                    {
                        IF_ImplicationCuLeRuleDef l_IF_ImplicationCuLeRuleDef = (IF_ImplicationCuLeRuleDef)i_CuLeRuleDef;

                        CuLeRule l_CuLeRule_IF   = this.CreateCuLeRule(l_IF_ImplicationCuLeRuleDef.CuLeRuleDef_IF(), i_CuLeQuantifierList, i_State);
                        CuLeRule l_CuLeRule_THEN = this.CreateCuLeRule(l_IF_ImplicationCuLeRuleDef.CuLeRuleDef_THEN(), i_CuLeQuantifierList, i_State);

                        return(new IF_ImplicationCuLeRule(l_CuLeRule_IF, l_CuLeRule_THEN));
                    }
                    if (i_CuLeRuleDef is IF_ELSE_ImplicationCuLeRuleDef)
                    {
                        IF_ELSE_ImplicationCuLeRuleDef l_IF_ELSE_ImplicationCuLeRuleDef = (IF_ELSE_ImplicationCuLeRuleDef)i_CuLeRuleDef;

                        CuLeRule l_CuLeRule_IF   = this.CreateCuLeRule(l_IF_ELSE_ImplicationCuLeRuleDef.CuLeRuleDef_IF(), i_CuLeQuantifierList, i_State);
                        CuLeRule l_CuLeRule_THEN = this.CreateCuLeRule(l_IF_ELSE_ImplicationCuLeRuleDef.CuLeRuleDef_THEN(), i_CuLeQuantifierList, i_State);
                        CuLeRule l_CuLeRule_ELSE = this.CreateCuLeRule(l_IF_ELSE_ImplicationCuLeRuleDef.CuLeRuleDef_ELSE(), i_CuLeQuantifierList, i_State);

                        return(new IF_ELSE_ImplicationCuLeRule(l_CuLeRule_IF, l_CuLeRule_THEN, l_CuLeRule_ELSE));
                    }
                }
                if (i_CuLeRuleDef is EquivalenceCuLeRuleDef)
                {
                    EquivalenceCuLeRuleDef l_EquivalenceCuLeRuleDef = (EquivalenceCuLeRuleDef)i_CuLeRuleDef;

                    CuLeRule l_CuLeRule_A = this.CreateCuLeRule(l_EquivalenceCuLeRuleDef.CuLeRuleDef_A(), i_CuLeQuantifierList, i_State);
                    CuLeRule l_CuLeRule_B = this.CreateCuLeRule(l_EquivalenceCuLeRuleDef.CuLeRuleDef_B(), i_CuLeQuantifierList, i_State);

                    return(new EquivalenceCuLeRule(l_CuLeRule_A, l_CuLeRule_B));
                }
            }

            throw new ArgumentException("Rule Definition Error");
        }// End of Create CuLeRule