Exemple #1
0
        private AssertionBase createReachability(AssertionExpr assertion)
        {
            Spec.ExecProcessDatabase.TryGetValue(assertion.Target, out DefinitionRef execProc);
            ADLAssertionReachability assertionCSP = new ADLAssertionReachability(execProc, assertion.Expression);

            //Spec.DeclarationDatabase.Add(assertion.Expression, new Expression());
            // TODO: need to revise this to work
            return(assertionCSP);
        }
Exemple #2
0
        public override object VisitAssertion([NotNull] AssertionContext context)
        {
            Console.WriteLine("visit asssertion " + context.verification().ID());
            AssertionExpr assert = new AssertionExpr(context.verification().ID().GetText());

            if (context.verification().DEADLOCKFREE() != null)
            {
                assert.Type = AssertionExpr.AssertionType.deadlockfree;
            }
            else if (context.verification().CIRCULARFREE() != null)
            {
                assert.Type = AssertionExpr.AssertionType.circularfree;
            }
            else if (context.verification().BOTTLENECKFREE() != null)
            {
                assert.Type = AssertionExpr.AssertionType.bottleneckfree;
            }
            else if (context.verification().AMBIGUOUSINTERFACEFREE() != null)
            {
                assert.Type = AssertionExpr.AssertionType.ambiguousinterface;
            }
            else if (context.verification().LAVAFLOWFREE() != null)
            {
                assert.Type = AssertionExpr.AssertionType.lavaflow;
            }
            else if (context.verification().DECOMPOSITIONFREE() != null)
            {
                assert.Type = AssertionExpr.AssertionType.decomposition;
            }
            else if (context.verification().POLTERGEISTSFREE() != null)
            {
                assert.Type = AssertionExpr.AssertionType.poltergeists;
            }
            else if (context.verification().reachexpr() != null)
            {
                assert.Type       = AssertionExpr.AssertionType.reachability;
                assert.Expression = context.verification().reachexpr().ID().GetText().Trim();
            }
            else if (context.verification().ltlexpr() != null)
            {
                String ltlexpr = context.verification().ltlexpr().GetText();
                foreach (var token in context.verification().ltlexpr().children)
                {
                    Console.WriteLine("     LTL=== " + token.GetText());
                }
                assert.Expression        = ltlexpr.Substring(ltlexpr.IndexOf("|=") + 2);
                assert.ExpressionContext = context.verification().ltlexpr();
                assert.Type = AssertionExpr.AssertionType.LTL;
            }

            return(assert);
        }
Exemple #3
0
 public void AddAssertion(AssertionExpr assertion, string options)
 {
     if (assertion.Type == AssertionExpr.AssertionType.deadlockfree)
     {
         AssertionBase asrt = createDeadlockAssertion(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + "-deadlockfree", asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.circularfree)
     {
         AssertionBase asrt = createCircularAssertion(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + "-circularfree", asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.bottleneckfree)
     {
         AssertionBase asrt = createBottleneckAssertion(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + "-bottleneckfree", asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.ambiguousinterface)
     {
         AssertionBase asrt = createAmbiguousInterfaceAssertion(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + "-ambiguousinterface", asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.lavaflow)
     {
         AssertionBase asrt = createLavaFlowAssertion(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + "-lavaflow", asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.decomposition)
     {
         AssertionBase asrt = createDecompositionAssertion(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + "-decomposition", asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.poltergeists)
     {
         AssertionBase asrt = createPoltergeistAssertion(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + "-poltergeist", asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.LTL)
     {
         AssertionBase asrt = createLTLAssertion(assertion, options);
         Spec.AssertionDatabase.Add(assertion.Target + " " + assertion.Expression, asrt);
     }
     else if (assertion.Type == AssertionExpr.AssertionType.reachability)
     {
         AssertionBase asrt = createReachability(assertion);
         Spec.AssertionDatabase.Add(assertion.Target + " reaches " + assertion.Expression, asrt);
     }
 }
Exemple #4
0
        private AssertionBase createCircularAssertion(AssertionExpr assertion)
        {
            Spec.ExecProcessDatabase.TryGetValue(assertion.Target, out DefinitionRef execProc);
            // insert assertion
            ADLAssertionCircular assertionCSP = null;

            if (execProc != null)
            {
                assertionCSP = new ADLAssertionCircular(execProc);
            }
            else
            {
                throw new Exception("Unknown target process for assertion");
            }

            return(assertionCSP);
        }
Exemple #5
0
        private AssertionBase createPoltergeistAssertion(AssertionExpr assertion)
        {
            Spec.ExecProcessDatabase.TryGetValue(assertion.Target, out DefinitionRef execProc);
            // insert assertion
            ADLAssertionPoltergeist assertionCSP = null;

            if (execProc != null)
            {
                assertionCSP = new ADLAssertionPoltergeist(execProc);
                assertionCSP.ComponentDatabase = Spec.ComponentDatabase;
            }
            else
            {
                throw new Exception("Unknown target process for assertion");
            }

            return(assertionCSP);
        }
Exemple #6
0
        private AssertionBase createLTLAssertion(AssertionExpr assertion, string options)
        {
            Spec.ExecProcessDatabase.TryGetValue(assertion.Target, out DefinitionRef execProc);
            ADLAssertionLTL assertLTL = null;

            if (execProc != null)
            {
                String ltl = assertion.Expression.Trim();
                // Update LTL state
                if (ltl.IndexOf(".") != -1)
                {
                    ltl = ltl.Replace('.', '_');
                }


                // create ADLAssertionLTL
                assertLTL = new ADLAssertionLTL(execProc, ltl);
                BuchiAutomata PositiveBA = LTL2BA.FormulaToBA(ltl, options, null);
                // default to false for x operator U X V T F R  NOT SUPPORTED for now
                bool hasXoperator = false;
                PositiveBA.HasXOperator = hasXoperator;
                if (!LivenessChecking.isLiveness(PositiveBA))
                {
                    assertLTL.SeteBAs(null, PositiveBA);
                }
                else
                {
                    BuchiAutomata BA = LTL2BA.FormulaToBA("!(" + ltl + ")", options, null); //.Replace(".", Ultility.Ultility.DOT_PREFIX)
                    BA.HasXOperator = hasXoperator;
                    assertLTL.SeteBAs(BA, PositiveBA);
                }
            }
            else
            {
                throw new Exception("Unknown target process for assertion");
            }

            return(assertLTL);
        }
Exemple #7
0
        /// <summary>
        /// Parse the specification from string input into objects
        /// </summary>
        /// <param name="spec">string input of the model</param>
        /// <param name="option">option for LTL parsing, usually it is an empty string</param>
        protected virtual void ParseSpec(string spec, string options)
        {
            System.Diagnostics.Debug.WriteLine("parsing spec... ");

            IsParsing = true;

            if (GlobalConstantDatabase == null)
            {
                GlobalConstantDatabase = new Dictionary <string, Expression>();
            }

            // Start parsing ADL
            AntlrInputStream inputStream = new AntlrInputStream(spec);
            ADLLexer         speakLexer  = new ADLLexer(inputStream);

            Antlr4.Runtime.CommonTokenStream commonTokenStream = new Antlr4.Runtime.CommonTokenStream(speakLexer);

            ADL_Parser.ADLParser parser = new ADL_Parser.ADLParser(commonTokenStream);

            ADLVisitor visitor = new ADLVisitor();

            Object           element;
            StatementContext statement;
            CSPGenerator     generator = new CSPGenerator(this);

            while (true)
            {
                statement = parser.statement();

                // parsing architecture elements
                if ((element = statement.archelement()) != null)
                {
                    element = visitor.Visit((ArchelementContext)element);

                    if (element is Component)
                    {
                        Component comp = (Component)element;
                        Console.WriteLine(comp.ToString());
                        ComponentDatabase.Add(comp.Name, comp);
                    }
                    else if (element is Connector)
                    {
                        Connector conn = ((Connector)element);
                        Console.WriteLine(conn.ToString());
                        ConnectorDatabase.Add(conn.Name, conn);
                    }
                    else if (element is SystemConfig)
                    {
                        Console.WriteLine(((SystemConfig)element).ToString());
                        // Console.WriteLine("system:"+((SystemConfig)element).ToString());
                        generator.parse((SystemConfig)element);
                    }

                    // parsing assetion
                }
                else if ((element = statement.assertion()) != null)
                {
                    AssertionExpr assertion = (AssertionExpr)visitor.VisitAssertion((AssertionContext)element);
                    Console.WriteLine(assertion.ToString());
                    generator.AddAssertion(assertion, options);
                }
                else
                {
                    break;
                }
            }

            // End parsing ADL


            StaticAnalysis();
            CheckingConflictingEventsAndVariables();

            foreach (KeyValuePair <string, Definition> pair in DefinitionDatabase)
            {
                List <string> gVar = pair.Value.GlobalVars;

                int i = 0;
                while (i < gVar.Count)
                {
                    //Console.WriteLine("parsed " + gVar[i]);
                    if (SpecValuation.Variables != null && !SpecValuation.Variables.ContainsKey(gVar[i]))
                    {
                        gVar.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }
            }

            //get the relevant channels;
            if (ChannelDatabase.Count > 0)
            {
                SyncrhonousChannelNames = new List <string>(0);
                Dictionary <string, ChannelQueue> newChannelDatabase = new Dictionary <string, ChannelQueue>();

                foreach (KeyValuePair <string, ChannelQueue> pair in ChannelDatabase)
                {
                    if (pair.Value.Size == 0)
                    {
                        SyncrhonousChannelNames.Add(pair.Key);
                    }
                    else
                    {
                        newChannelDatabase.Add(pair.Key, pair.Value);
                    }
                }

                SpecValuation.Channels = newChannelDatabase;
                HasSyncrhonousChannel  = SyncrhonousChannelNames.Count > 0;
            }

            foreach (KeyValuePair <string, AssertionBase> entry in AssertionDatabase)
            {
                entry.Value.Initialize(this);
            }

            CheckVariableRange();
            // Console.WriteLine("Finish parsing spec....................");
            Console.WriteLine(this.GetSpecification());
        }