public static void PopulateDeclarations( ITranslationErrorHandler handler, Scope topLevelScope, PParser.ProgramContext context, ParseTreeProperty <IPDecl> nodesToDeclarations) { var visitor = new DeclarationVisitor(handler, topLevelScope, nodesToDeclarations); visitor.Visit(context); }
private static Scope BuildGlobalScope(ITranslationErrorHandler handler, PParser.ProgramContext[] programUnits) { var globalScope = new Scope(handler); var nodesToDeclarations = new ParseTreeProperty <IPDecl>(); // Add built-in events to the table. globalScope.Put("halt", (PParser.EventDeclContext)null); globalScope.Put("null", (PParser.EventDeclContext)null); // Step 1: Create mapping of names to declaration stubs foreach (PParser.ProgramContext programUnit in programUnits) { DeclarationStubVisitor.PopulateStubs(globalScope, programUnit, nodesToDeclarations); } // Step 2: Validate declarations and fill with types foreach (PParser.ProgramContext programUnit in programUnits) { DeclarationVisitor.PopulateDeclarations(handler, globalScope, programUnit, nodesToDeclarations); } return(globalScope); }