コード例 #1
0
        public static void PopulateDeclarations(
            ITranslationErrorHandler handler,
            Scope topLevelScope,
            PParser.ProgramContext context,
            ParseTreeProperty <IPDecl> nodesToDeclarations)
        {
            var visitor = new DeclarationVisitor(handler, topLevelScope, nodesToDeclarations);

            visitor.Visit(context);
        }
コード例 #2
0
ファイル: Analyzer.cs プロジェクト: zhaowei19920524/P
        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);
        }