public override object VisitNamedModuleDecl([NotNull] PParser.NamedModuleDeclContext context) { string symbolName = context.name.GetText(); NamedModule decl = CurrentScope.Put(symbolName, context); nodesToDeclarations.Put(context, decl); return(null); }
public NamedModule Put(string name, PParser.NamedModuleDeclContext tree) { NamedModule namedModule = new NamedModule(tree, name); CheckConflicts(namedModule, Namespace(namedModules)); namedModules.Add(name, namedModule); return(namedModule); }
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); } }
public override IPModuleExpr VisitNamedModule([NotNull] PParser.NamedModuleContext context) { // check if the named module is declared if (!globalScope.Get(context.GetText(), out NamedModule mod)) { throw handler.MissingDeclaration(context, "module", context.GetText()); } PParser.NamedModuleDeclContext declContext = (PParser.NamedModuleDeclContext)mod.SourceLocation; return(Visit(declContext.modExpr())); }