//----------------------------------------------------------------------------- // Primary Worker. This drives the different stages. // Returns the error code for all expected end-user errors. // Unexpected errors (bugs / holes in the compiler) will throw an exception. //----------------------------------------------------------------------------- static int MainWorker(string[] arstSourceFiles) { if (arstSourceFiles == null) { PrintError_NoSourceFiles(); return(1); } // Check if debugging the lexer. Just do first file // @todo - should we do all files? if (ShouldDebugQuit(EStage.cLexer)) { string stDefault = arstSourceFiles[0]; System.IO.StreamReader reader = new System.IO.StreamReader(stDefault); ILexer lex = new ManualParser.Lexer(stDefault, reader); return(TestLexer(lex)); } // // Lex & Parse all source files. // It doesn't matter which order files are parsed in // AST.ProgramDecl root = ParseAllFiles(arstSourceFiles); if (root == null) { return(1); } if (ShouldDebugQuit(EStage.cParser)) { return(0); } // // Symantic checks: // // Must startup codegen so that it can assign clr types m_codegen.BeginOutput(arstSourceFiles); System.Reflection.Assembly [] refs = LoadImportedAssemblies(); if (StdErrorLog.HasErrors()) { return(19); } ICLRtypeProvider provider = m_codegen.GetProvider(refs); ISemanticChecker check = new SymbolEngine.SemanticChecker(); bool fCheckOk = check.DoCheck(root, provider, refs); if (!fCheckOk) { return(2); } // Dump parse tree after resolution if (s_fGenerateXML) { string stOutput = IO.Path.GetFileNameWithoutExtension(arstSourceFiles[0]); System.Xml.XmlWriter oSym = new System.Xml.XmlTextWriter(stOutput + "_sym.xml", null); check.DumpSymbolTable(oSym); System.Xml.XmlWriter oPost = new System.Xml.XmlTextWriter(stOutput + "_post.xml", null); AST.Node.DumpTree(root, oPost); } if (ShouldDebugQuit(EStage.cSymbolResolution)) { return(0); } // // Codegen // m_codegen.DoCodeGen(root); m_codegen.EndOutput(); // If we make it this far, we have no errors. return(0); }
//----------------------------------------------------------------------------- // Main checking routine // Return true if successful, else false //----------------------------------------------------------------------------- public bool DoCheck( AST.ProgramDecl p, ICLRtypeProvider provider, Assembly [] refs ) { Debug.Assert(provider != null); Debug.Assert(p != null); m_provider = provider; string stSubPhase = ""; try { m_scopeGlobal = new Scope("Global", null, null); // Import symbols stSubPhase = "importing assemblies"; ImportAssembly(GetMscorlib()); AddDefaultTypes(m_scopeGlobal); foreach(Assembly a in refs) { ImportAssembly(a); } // Pass 1 - Resolve the namespaces and stub the types. // This will stub all scopes and create a lexical-scope tree. stSubPhase = "resolving namespaces"; p.ResolveNamespace(this, m_scopeGlobal); // Pass 2 - Resolve Types (to both CLR & Blue) stSubPhase = "resolving to clr types"; p.ResolveTypes(this, provider); // Pass 3 - resolve class member declarations (Methods & fields) stSubPhase = "resolving member declarations"; p.ResolveMemberDecls(this, provider); // Pass 4 - resolve method bodies stSubPhase = "resolving member bodies"; p.ResolveBodies(this); // Final Debug verify before codegen stSubPhase = "final debug check"; p.DebugCheck(this); m_scopeGlobal.DebugCheck(this); p.NotifyResolutionDone(); return true; } // Strip away SymbolErrors; we've already reported them when we first threw them. catch (SymbolError.SymbolErrorException) { return false; } catch(System.Exception e) { Blue.Driver.PrintError_InternalError(e, "Symbol Resolution(" + stSubPhase + ")"); return false; } }