Ejemplo n.º 1
0
        public static void PopulateStubs(
            Scope globalScope,
            PParser.ProgramContext context,
            ParseTreeProperty <IPDecl> nodesToDeclarations)
        {
            var visitor = new DeclarationStubVisitor(globalScope, nodesToDeclarations);

            visitor.Visit(context);
        }
Ejemplo n.º 2
0
        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);
        }