Beispiel #1
0
        private static ICondition extractGuardConditionFromKpGuard(IGuard guard)
        {
            ICondition condition = null;

            if (guard is BasicGuard)
            {
                BasicGuard basicGuard = (BasicGuard)guard;
                condition = getBoolExpression(basicGuard);
            }
            else if (guard is NegatedGuard)
            {
                NegatedGuard negatedGuard = (NegatedGuard)guard;
                Console.Error.WriteLine("KP NegatedGuard to SMV translation has not been implemented yet!");
            }
            else if (guard is CompoundGuard)
            {
                CompoundGuard          compoundGuard    = (CompoundGuard)guard;
                CompoundBoolExpression compoundBoolExpr = new CompoundBoolExpression();
                compoundBoolExpr.LeftCondition  = extractGuardConditionFromKpGuard(compoundGuard.Lhs);
                compoundBoolExpr.BinaryOperator = SMVUtil.getBinaryOperator(compoundGuard.Operator);
                compoundBoolExpr.RightCondition = extractGuardConditionFromKpGuard(compoundGuard.Rhs);
                condition = compoundBoolExpr;
            }
            return(condition);
        }
        private static ICondition extractConditionFromKpGuard(Module sourceModule, IGuard guard)
        {
            ICondition condition = null;

            if (guard is BasicGuard)
            {
                BasicGuard basicGuard = (BasicGuard)guard;
                condition = getBoolExpression(sourceModule, basicGuard);
            }
            else if (guard is NegatedGuard)
            {
                NegatedGuard negatedGuard = (NegatedGuard)guard;
                Console.Error.WriteLine("NegatedGuard is not applicable.");
                // ICondition negatedBooleanExpression = getNegatedGuard(negatedGuard);
            }
            else if (guard is CompoundGuard)
            {
                CompoundGuard          compoundGuard    = (CompoundGuard)guard;
                CompoundBoolExpression compoundBoolExpr = null;
                compoundBoolExpr.LeftCondition  = extractConditionFromKpGuard(sourceModule, compoundGuard.Lhs);
                compoundBoolExpr.BinaryOperator = SMVUtil.getBinaryOperator(compoundGuard.Operator);
                compoundBoolExpr.RightCondition = extractConditionFromKpGuard(sourceModule, compoundGuard.Rhs);
                condition = compoundBoolExpr;
            }
            return(condition);
        }
Beispiel #3
0
        private void Guard(List <int> list, IGuard guard, bool negated = false)
        {
            if (guard is BasicGuard)
            {
                BasicGuard basicGuard = (BasicGuard)guard;
                int        rel        = 0;
                switch (basicGuard.Operator)
                {
                case RelationalOperator.LT: rel = 0; break;

                case RelationalOperator.LEQ: rel = 1; break;

                case RelationalOperator.EQUAL: rel = 2; break;

                case RelationalOperator.NOT_EQUAL: rel = 3; break;

                case RelationalOperator.GT: rel = 4; break;

                case RelationalOperator.GEQ: rel = 5; break;
                }
                if (negated)
                {
                    rel += 8;
                }
                list.Add(rel);
                Multiset multiset = basicGuard.Multiset;
                string   o        = multiset.Objects.ToList()[0];
                list.Add(objectsId[o]);
                list.Add(multiset[o]);
            }
            else
            if (guard is NegatedGuard)
            {
                NegatedGuard negatedGuard = (NegatedGuard)guard;
                Guard(list, negatedGuard.Operand, true);
            }
            else
            if (guard is CompoundGuard)
            {
                CompoundGuard compoundGuard = (CompoundGuard)guard;
                int           op;
                if (compoundGuard.Operator == BinaryGuardOperator.AND)
                {
                    op = 0;
                }
                else
                {
                    op = 1;
                }
                Guard(list, compoundGuard.Lhs, negated);
                list.Add(op);
                Guard(list, compoundGuard.Rhs, negated);
            }
        }
Beispiel #4
0
        public void writeGuard(IGuard g)
        {
            if (g == null)
            {
                return;
            }
            owt.Write("{");
            if (g is BasicGuard)
            {
                BasicGuard bg = g as BasicGuard;
                owt.Write("\"operator\":");
                switch (bg.Operator)
                {
                case RelationalOperator.EQUAL: owt.Write("\"eq\""); break;

                case RelationalOperator.GEQ: owt.Write("\"geq\""); break;

                case RelationalOperator.GT: owt.Write("\"gt\""); break;

                case RelationalOperator.LT: owt.Write("\"lt\""); break;

                case RelationalOperator.LEQ: owt.Write("\"leq\""); break;

                case RelationalOperator.NOT_EQUAL: owt.Write("\"neq\""); break;
                }
                owt.Write(", \"multiset\":");
                writeMultiset(bg.Multiset);
            }
            else if (g is NegatedGuard)
            {
                NegatedGuard ng = g as NegatedGuard;
                owt.Write("\"operator\":\"not\"");
                owt.Write(", \"operatnd\":");
                writeGuard(ng.Operand);
            }
            else if (g is CompoundGuard)
            {
                CompoundGuard cg = g as CompoundGuard;
                owt.Write("\"operator\":");
                switch (cg.Operator)
                {
                case BinaryGuardOperator.AND: owt.Write("\"and\""); break;

                case BinaryGuardOperator.OR: owt.Write("\"or\""); break;
                }
                owt.Write(", \"lhs\":");
                writeGuard(cg.Lhs);
                owt.Write(", \"rhs\":");
                writeGuard(cg.Rhs);
            }
            owt.Write("}");
        }
Beispiel #5
0
 private static void extractVarsFromGuards(KPsystem kpSystem, MType kpType, Module module, IGuard guard)
 {
     if (guard is BasicGuard)
     {
         BasicGuard basicGuard = (BasicGuard)guard;
         extractVarFromBasicGuards(kpSystem, kpType, module, basicGuard);
     }
     else if (guard is NegatedGuard)
     {
         NegatedGuard negatedGuard = (NegatedGuard)guard;
         Console.Error.WriteLine("This part has not implemented yet.");
         // ICondition negatedBooleanExpression = getNegatedGuard(negatedGuard);
     }
     else if (guard is CompoundGuard)
     {
         CompoundGuard compoundGuard = (CompoundGuard)guard;
         extractVarsFromGuards(kpSystem, kpType, module, compoundGuard.Lhs);
         extractVarsFromGuards(kpSystem, kpType, module, compoundGuard.Rhs);
     }
 }
        public static string Guard(IGuard guard)
        {
            StringBuilder buf = new StringBuilder();

            if (guard is BasicGuard)
            {
                BasicGuard g = guard as BasicGuard;
                switch (g.Operator)
                {
                case RelationalOperator.EQUAL: {
                    buf.Append("=");
                } break;

                case RelationalOperator.NOT_EQUAL: {
                    buf.Append("!");
                } break;

                case RelationalOperator.GEQ: {
                    buf.Append(">=");
                } break;

                case RelationalOperator.LEQ: {
                    buf.Append("<=");
                } break;

                case RelationalOperator.LT: {
                    buf.Append("<");
                } break;

                case RelationalOperator.GT: {
                    buf.Append(">");
                } break;
                }

                buf.Append(Multiset(g.Multiset));
            }
            else if (guard is NegatedGuard)
            {
                NegatedGuard g = guard as NegatedGuard;
                buf.AppendFormat("!({0})", Guard(g.Operand));
            }
            else if (guard is CompoundGuard)
            {
                CompoundGuard g = guard as CompoundGuard;

                bool useP = false;
                if (g.Lhs is CompoundGuard)
                {
                    CompoundGuard cgLhs = g.Lhs as CompoundGuard;
                    if (cgLhs.Operator != g.Operator)
                    {
                        useP = true;
                    }
                }

                if (useP)
                {
                    buf.Append("(").Append(Guard(g.Lhs)).Append(")");
                }
                else
                {
                    buf.Append(Guard(g.Lhs));
                }

                if (g.Operator == BinaryGuardOperator.AND)
                {
                    buf.Append(" & ");
                }
                else
                {
                    buf.Append(" | ");
                }

                useP = false;
                if (g.Rhs is CompoundGuard)
                {
                    CompoundGuard cgRhs = g.Rhs as CompoundGuard;
                    if (cgRhs.Operator != g.Operator)
                    {
                        useP = true;
                    }
                }

                if (useP)
                {
                    buf.Append("(").Append(Guard(g.Rhs)).Append(")");
                }
                else
                {
                    buf.Append(Guard(g.Rhs));
                }
            }


            return(buf.ToString());
        }
Beispiel #7
0
        private string Guard(IGuard guard, bool negated = false, int ooperation = 0)
        {
            StringBuilder sb = new StringBuilder();

            if (guard is BasicGuard)
            {
                BasicGuard basicGuard = (BasicGuard)guard;
                int        rel        = 0;
                switch (basicGuard.Operator)
                {
                case RelationalOperator.LT: rel = 0; break;

                case RelationalOperator.LEQ: rel = 1; break;

                case RelationalOperator.EQUAL: rel = 2; break;

                case RelationalOperator.NOT_EQUAL: rel = 3; break;

                case RelationalOperator.GT: rel = 4; break;

                case RelationalOperator.GEQ: rel = 5; break;
                }
                if (negated)
                {
                    rel += 7;
                }
                sb.Append("{");
                sb.AppendFormat("{0}, ", rel);
                Multiset multiset = basicGuard.Multiset;
                sb.Append("{");
                string o = multiset.Objects.ToList()[0];
                sb.Append(string.Format("{0}, {1}", objectsId[o], multiset[o]));
                sb.Append("}");
                sb.AppendFormat(", {0}", ooperation);
                sb.Append("}");
            }
            else
            if (guard is NegatedGuard)
            {
                NegatedGuard negatedGuard = (NegatedGuard)guard;
                sb.Append(Guard(negatedGuard.Operand, true));
            }
            else
            if (guard is CompoundGuard)
            {
                CompoundGuard compoundGuard = (CompoundGuard)guard;
                int           op;
                if (compoundGuard.Operator == BinaryGuardOperator.AND)
                {
                    op = 0;
                }
                else
                {
                    op = 1;
                }
                sb.Append(Guard(compoundGuard.Lhs, negated, op));
                sb.Append(", ");
                sb.Append(Guard(compoundGuard.Rhs, negated, ooperation));
            }
            return(sb.ToString());
        }