public override object VisitSafetyTestDecl([NotNull] PParser.SafetyTestDeclContext context)
        {
            string     symbolName = context.testName.GetText();
            SafetyTest decl       = CurrentScope.Put(symbolName, context);

            decl.Main = context.mainMachine?.GetText();
            nodesToDeclarations.Put(context, decl);
            return(null);
        }
Exemple #2
0
        public static void PopulateAllModuleExprs(
            ITranslationErrorHandler handler,
            Scope globalScope)
        {
            ModuleExprVisitor modExprVisitor = new ModuleExprVisitor(handler, globalScope);

            // first do all the named modules
            foreach (NamedModule mod in globalScope.NamedModules)
            {
                PParser.NamedModuleDeclContext context = (PParser.NamedModuleDeclContext)mod.SourceLocation;
                mod.ModExpr = modExprVisitor.Visit(context.modExpr());
            }

            // all the test declarations
            foreach (SafetyTest test in globalScope.SafetyTests)
            {
                PParser.SafetyTestDeclContext context = (PParser.SafetyTestDeclContext)test.SourceLocation;
                test.ModExpr = modExprVisitor.Visit(context.modExpr());
            }

            foreach (RefinementTest test in globalScope.RefinementTests)
            {
                PParser.RefinementTestDeclContext context = (PParser.RefinementTestDeclContext)test.SourceLocation;
                test.LeftModExpr  = modExprVisitor.Visit(context.modExpr()[0]);
                test.RightModExpr = modExprVisitor.Visit(context.modExpr()[1]);
            }

            if (globalScope.Implementations.Any())
            {
                // all user defind implementations
                foreach (Implementation impl in globalScope.Implementations)
                {
                    PParser.ImplementationDeclContext context = (PParser.ImplementationDeclContext)impl.SourceLocation;
                    impl.ModExpr = modExprVisitor.Visit(context.modExpr());
                }
            }
            else if (!globalScope.SafetyTests.Any())
            {
                Implementation defaultImplDecl = new Implementation(ParserRuleContext.EmptyContext, "DefaultImpl")
                {
                    Main = "Main"
                };
                // create bindings from each machine to itself
                List <Tuple <Interface, Machine> > defaultBindings = new List <Tuple <Interface, Machine> >();
                foreach (Machine machine in globalScope.Machines.Where(m => !m.IsSpec))
                {
                    globalScope.Get(machine.Name, out Interface @interface);
                    defaultBindings.Add(new Tuple <Interface, Machine>(@interface, machine));
                }

                defaultImplDecl.ModExpr = new BindModuleExpr(ParserRuleContext.EmptyContext, defaultBindings);

                globalScope.AddDefaultImpl(defaultImplDecl);
            }
        }
Exemple #3
0
        public SafetyTest Put(string name, PParser.SafetyTestDeclContext tree)
        {
            SafetyTest safetyTest = new SafetyTest(tree, name);

            CheckConflicts(safetyTest,
                           Namespace(implementations),
                           Namespace(safetyTests),
                           Namespace(refinementTests));
            safetyTests.Add(name, safetyTest);
            return(safetyTest);
        }