diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-12-19 22:51:13 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-12-19 22:51:13 +0000 |
commit | 95041a2029a069386ee67439f6d0fb524a9d184f (patch) | |
tree | fc90277b24345b3b96aa34852ac44656e513e361 /Driver | |
parent | 7dcc968f17a6ff9088c9651dddccc8d4025a1271 (diff) |
Interned MainFileID within SourceManager. Since SourceManager is referenced by
both Preprocessor and ASTContext, we no longer need to explicitly pass
MainFileID around in function calls that also pass either Preprocessor or
ASTContext. This resulted in some nice cleanups in the ASTConsumers and the
driver.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45228 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver')
-rw-r--r-- | Driver/ASTConsumers.cpp | 14 | ||||
-rw-r--r-- | Driver/DiagChecker.cpp | 16 | ||||
-rw-r--r-- | Driver/PrintPreprocessedOutput.cpp | 4 | ||||
-rw-r--r-- | Driver/RewriteTest.cpp | 6 | ||||
-rw-r--r-- | Driver/SerializationTest.cpp | 2 | ||||
-rw-r--r-- | Driver/clang.cpp | 22 | ||||
-rw-r--r-- | Driver/clang.h | 7 |
7 files changed, 34 insertions, 37 deletions
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 02e30d31b1..add349ce82 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -356,7 +356,7 @@ namespace { public: ASTDumper() : DeclPrinter() {} - void Initialize(ASTContext &Context, unsigned MainFileID) { + void Initialize(ASTContext &Context) { SM = &Context.getSourceManager(); } @@ -400,7 +400,7 @@ namespace { class ASTViewer : public ASTConsumer { SourceManager *SM; public: - void Initialize(ASTContext &Context, unsigned MainFileID) { + void Initialize(ASTContext &Context) { SM = &Context.getSourceManager(); } @@ -482,7 +482,7 @@ namespace { class LivenessVisitor : public CFGVisitor { SourceManager *SM; public: - virtual void Initialize(ASTContext &Context, unsigned MainFileID) { + virtual void Initialize(ASTContext &Context) { SM = &Context.getSourceManager(); } @@ -507,7 +507,7 @@ namespace { ASTContext *Ctx; public: DeadStoreVisitor(Diagnostic &diags) : Diags(diags) {} - virtual void Initialize(ASTContext &Context, unsigned MainFileID) { + virtual void Initialize(ASTContext &Context) { Ctx = &Context; } @@ -530,7 +530,7 @@ namespace { ASTContext *Ctx; public: UninitValsVisitor(Diagnostic &diags) : Diags(diags) {} - virtual void Initialize(ASTContext &Context, unsigned MainFileID) { + virtual void Initialize(ASTContext &Context) { Ctx = &Context; } @@ -565,7 +565,7 @@ namespace { LLVMEmitter(Diagnostic &diags, const LangOptions &LO) : Diags(diags) , Features(LO) {} - virtual void Initialize(ASTContext &Context, unsigned MainFileID) { + virtual void Initialize(ASTContext &Context) { Ctx = &Context; M = new llvm::Module("foo"); M->setTargetTriple(Ctx->Target.getTargetTriple()); @@ -618,7 +618,7 @@ namespace { const LangOptions &LO) : Diags(diags), TU(LO), FName(F) {} - virtual void Initialize(ASTContext &Context, unsigned MainFileID) { + virtual void Initialize(ASTContext &Context) { TU.setContext(&Context); } diff --git a/Driver/DiagChecker.cpp b/Driver/DiagChecker.cpp index 53eed43c2c..cc5dd7512e 100644 --- a/Driver/DiagChecker.cpp +++ b/Driver/DiagChecker.cpp @@ -82,16 +82,16 @@ static void FindDiagnostics(const std::string &Comment, } } -/// FindExpectedDiags - Lex the file to finds all of the expected errors and -/// warnings. -static void FindExpectedDiags(Preprocessor &PP, unsigned MainFileID, +/// FindExpectedDiags - Lex the main source file to find all of the +// expected errors and warnings. +static void FindExpectedDiags(Preprocessor &PP, DiagList &ExpectedErrors, DiagList &ExpectedWarnings) { // Return comments as tokens, this is how we find expected diagnostics. PP.SetCommentRetentionState(true, true); // Enter the cave. - PP.EnterMainSourceFile(MainFileID); + PP.EnterMainSourceFile(); // Turn off all warnings from relexing or preprocessing. PP.getDiagnostics().setWarnOnExtensions(false); @@ -225,14 +225,14 @@ static bool CheckResults(Preprocessor &PP, /// CheckASTConsumer - Implement diagnostic checking for AST consumers. -bool clang::CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, - ASTConsumer* C) { +bool clang::CheckASTConsumer(Preprocessor &PP, ASTConsumer* C) { + // Parse the AST and run the consumer, ultimately deleting C. - ParseAST(PP, MainFileID, C); + ParseAST(PP, C); // Gather the set of expected diagnostics. DiagList ExpectedErrors, ExpectedWarnings; - FindExpectedDiags(PP, MainFileID, ExpectedErrors, ExpectedWarnings); + FindExpectedDiags(PP, ExpectedErrors, ExpectedWarnings); // Check that the expected diagnostics occurred. return CheckResults(PP, ExpectedErrors, ExpectedWarnings); diff --git a/Driver/PrintPreprocessedOutput.cpp b/Driver/PrintPreprocessedOutput.cpp index 109664b8cc..0c8a62ee66 100644 --- a/Driver/PrintPreprocessedOutput.cpp +++ b/Driver/PrintPreprocessedOutput.cpp @@ -531,7 +531,7 @@ bool PrintPPOutputPPCallbacks::AvoidConcat(const Token &PrevTok, /// DoPrintPreprocessedInput - This implements -E mode. /// -void clang::DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP) { +void clang::DoPrintPreprocessedInput(Preprocessor &PP) { // Inform the preprocessor whether we want it to retain comments or not, due // to -C or -CC. PP.SetCommentRetentionState(EnableCommentOutput, EnableMacroCommentOutput); @@ -550,7 +550,7 @@ void clang::DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP) { // After we have configured the preprocessor, enter the main file. // Start parsing the specified input file. - PP.EnterMainSourceFile(MainFileID); + PP.EnterMainSourceFile(); // Consume all of the tokens that come from the predefines buffer. Those // should not be emitted into the output and are guaranteed to be at the diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index c5de070021..c9dd0f731c 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -62,7 +62,7 @@ namespace { static const int OBJC_ABI_VERSION =7 ; public: - void Initialize(ASTContext &context, unsigned mainFileID) { + void Initialize(ASTContext &context) { Context = &context; SM = &Context->getSourceManager(); MsgSendFunctionDecl = 0; @@ -81,7 +81,7 @@ namespace { SuperStructDecl = 0; // Get the ID and start/end of the main file. - MainFileID = mainFileID; + MainFileID = SM->getMainFileID(); const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID); MainFileStart = MainBuf->getBufferStart(); MainFileEnd = MainBuf->getBufferEnd(); @@ -123,7 +123,7 @@ namespace { "extern Protocol *objc_getProtocol(const char *);\n" "#include <objc/objc.h>\n"; - Rewrite.InsertText(SourceLocation::getFileLoc(mainFileID, 0), + Rewrite.InsertText(SourceLocation::getFileLoc(MainFileID, 0), s, strlen(s)); } diff --git a/Driver/SerializationTest.cpp b/Driver/SerializationTest.cpp index d43b570345..a668c7466b 100644 --- a/Driver/SerializationTest.cpp +++ b/Driver/SerializationTest.cpp @@ -42,7 +42,7 @@ public: ~SerializationTest(); - virtual void Initialize(ASTContext& context, unsigned) { + virtual void Initialize(ASTContext& context) { TU.setContext(&context); } diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 1bb4a1aa04..f38c83a6f8 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -878,9 +878,9 @@ static void InitializeIncludePaths(HeaderSearch &Headers, FileManager &FM, // Basic Parser driver //===----------------------------------------------------------------------===// -static void ParseFile(Preprocessor &PP, MinimalAction *PA, unsigned MainFileID){ +static void ParseFile(Preprocessor &PP, MinimalAction *PA){ Parser P(PP, *PA); - PP.EnterMainSourceFile(MainFileID); + PP.EnterMainSourceFile(); // Parsing the specified input file. P.ParseTranslationUnit(); @@ -963,7 +963,7 @@ static void ProcessInputFile(Preprocessor &PP, const std::string &InFile, case DumpTokens: { // Token dump mode. Token Tok; // Start parsing the specified input file. - PP.EnterMainSourceFile(MainFileID); + PP.EnterMainSourceFile(); do { PP.Lex(Tok); PP.DumpToken(Tok, true); @@ -975,7 +975,7 @@ static void ProcessInputFile(Preprocessor &PP, const std::string &InFile, case RunPreprocessorOnly: { // Just lex as fast as we can, no output. Token Tok; // Start parsing the specified input file. - PP.EnterMainSourceFile(MainFileID); + PP.EnterMainSourceFile(); do { PP.Lex(Tok); } while (Tok.isNot(tok::eof)); @@ -984,18 +984,17 @@ static void ProcessInputFile(Preprocessor &PP, const std::string &InFile, } case PrintPreprocessedInput: // -E mode. - DoPrintPreprocessedInput(MainFileID, PP); + DoPrintPreprocessedInput(PP); ClearSourceMgr = true; break; case ParseNoop: // -parse-noop - ParseFile(PP, new MinimalAction(PP.getIdentifierTable()), MainFileID); + ParseFile(PP, new MinimalAction(PP.getIdentifierTable())); ClearSourceMgr = true; break; case ParsePrintCallbacks: - ParseFile(PP, CreatePrintParserActionsAction(PP.getIdentifierTable()), - MainFileID); + ParseFile(PP, CreatePrintParserActionsAction(PP.getIdentifierTable())); ClearSourceMgr = true; break; @@ -1006,10 +1005,10 @@ static void ProcessInputFile(Preprocessor &PP, const std::string &InFile, if (Consumer) { if (VerifyDiagnostics) - exit(CheckASTConsumer(PP, MainFileID, Consumer)); + exit(CheckASTConsumer(PP, Consumer)); // This deletes Consumer. - ParseAST(PP, MainFileID, Consumer, Stats); + ParseAST(PP, Consumer, Stats); } if (Stats) { @@ -1062,8 +1061,7 @@ static void ProcessSerializedFile(const std::string& InFile, Diagnostic& Diag, exit (1); } - // FIXME: only work on consumers that do not require MainFileID. - Consumer->Initialize(*TU->getContext(), 0); + Consumer->Initialize(*TU->getContext()); for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I) Consumer->HandleTopLevelDecl(*I); diff --git a/Driver/clang.h b/Driver/clang.h index 77ce59ed1c..d6b7179b12 100644 --- a/Driver/clang.h +++ b/Driver/clang.h @@ -27,18 +27,17 @@ class IdentifierTable; class SourceManager; /// DoPrintPreprocessedInput - Implement -E mode. -void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP); +void DoPrintPreprocessedInput(Preprocessor &PP); /// CreatePrintParserActionsAction - Return the actions implementation that /// implements the -parse-print-callbacks option. MinimalAction *CreatePrintParserActionsAction(IdentifierTable &); /// EmitLLVMFromASTs - Implement -emit-llvm, which generates llvm IR from C. -void EmitLLVMFromASTs(Preprocessor &PP, unsigned MainFileID, - bool PrintStats); +void EmitLLVMFromASTs(Preprocessor &PP, bool PrintStats); /// CheckASTConsumer - Implement diagnostic checking for AST consumers. -bool CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, ASTConsumer* C); +bool CheckASTConsumer(Preprocessor &PP, ASTConsumer* C); } // end namespace clang |