]> granicus.if.org Git - clang/commitdiff
Interned MainFileID within SourceManager. Since SourceManager is referenced by
authorTed Kremenek <kremenek@apple.com>
Wed, 19 Dec 2007 22:51:13 +0000 (22:51 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 19 Dec 2007 22:51:13 +0000 (22:51 +0000)
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

12 files changed:
Driver/ASTConsumers.cpp
Driver/DiagChecker.cpp
Driver/PrintPreprocessedOutput.cpp
Driver/RewriteTest.cpp
Driver/SerializationTest.cpp
Driver/clang.cpp
Driver/clang.h
Lex/Preprocessor.cpp
Sema/ASTStreamer.cpp
include/clang/AST/ASTConsumer.h
include/clang/Lex/Preprocessor.h
include/clang/Sema/ASTStreamer.h

index 02e30d31b19b670724cfabf0ffcf2125d3dc1392..add349ce82e9be99bd5d870d58324472d5a5405e 100644 (file)
@@ -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);
     }
     
index 53eed43c2cc7ac05777acd09c60258240f6e3306..cc5dd7512e8609f561cdfa143bbafb0e4dff10c3 100644 (file)
@@ -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);
index 109664b8cc3b83f18fec00d64261c07afcde330f..0c8a62ee669d7537fc7f93f9e2f92d5e538f7ee0 100644 (file)
@@ -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
index c5de07002140cbdfc3b264e00600ec120399ab35..c9dd0f731cda609b42aeddd74a64b40b4c699ff8 100644 (file)
@@ -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));
     }
 
index d43b570345bcb3f83646946ce51e323f73c1e2f6..a668c7466b93bb1b3cef54df6b06375dfd7134bd 100644 (file)
@@ -42,7 +42,7 @@ public:
   
   ~SerializationTest();
 
-  virtual void Initialize(ASTContext& context, unsigned) {
+  virtual void Initialize(ASTContext& context) {
     TU.setContext(&context);
   }  
 
index 1bb4a1aa04f3d98fed468d9fcbb5584fff4d52ad..f38c83a6f8c0ce9b3433678dec93ac06c9c1c9fe 100644 (file)
@@ -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);
index 77ce59ed1c50b87a77273e258bd27617afb8130e..d6b7179b127e9bcac379c82a0363d59704f010eb 100644 (file)
@@ -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
index fb4628be712802364e3a8e169587cd22d1a3d7ad..a7880fa7fcb41ba83fa545c677e101e2b320c567 100644 (file)
@@ -431,7 +431,10 @@ static void InitializePredefinedMacros(Preprocessor &PP,
 
 /// EnterMainSourceFile - Enter the specified FileID as the main source file,
 /// which implicitly adds the builting defines etc.
-void Preprocessor::EnterMainSourceFile(unsigned MainFileID) {
+void Preprocessor::EnterMainSourceFile() {
+  
+  unsigned MainFileID = SourceMgr.getMainFileID();
+  
   // Enter the main file source buffer.
   EnterSourceFile(MainFileID, 0);
   
index b51874ca354c76a8b76c3a009142fa1a1f66f5ee..b6b63004135ea44db5455cb1524167d49ee7940b 100644 (file)
@@ -25,9 +25,10 @@ namespace {
   class ASTStreamer {
     Parser P;
   public:
-    ASTStreamer(Preprocessor &pp, ASTContext &ctxt, unsigned MainFileID)
+    ASTStreamer(Preprocessor &pp, ASTContext &ctxt)
       : P(pp, *new Sema(pp, ctxt)) {
-      pp.EnterMainSourceFile(MainFileID);
+        
+      pp.EnterMainSourceFile();
       
       // Initialize the parser.
       P.Initialize();
@@ -73,8 +74,7 @@ void ASTStreamer::PrintStats() const {
 /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
 /// the file is parsed.  This takes ownership of the ASTConsumer and
 /// ultimately deletes it.
-void clang::ParseAST(Preprocessor &PP, unsigned MainFileID, 
-                     ASTConsumer *Consumer, bool PrintStats) {
+void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
   // Collect global stats on Decls/Stmts (until we have a module streamer).
   if (PrintStats) {
     Decl::CollectingStats(true);
@@ -84,9 +84,9 @@ void clang::ParseAST(Preprocessor &PP, unsigned MainFileID,
   ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
                      PP.getIdentifierTable(), PP.getSelectorTable());
   
-  ASTStreamer Streamer(PP, Context, MainFileID);
+  ASTStreamer Streamer(PP, Context);
   
-  Consumer->Initialize(Context, MainFileID);
+  Consumer->Initialize(Context);
   
   while (Decl *D = Streamer.ReadTopLevelDecl())
     Consumer->HandleTopLevelDecl(D);
index 7221ab789b33859affa9f65b211f73c756673041..f0bc07dd34a98a3394cc2a8a105b247703b4c0ed 100644 (file)
@@ -26,8 +26,8 @@ public:
   virtual ~ASTConsumer();
   
   /// Initialize - This is called to initialize the consumer, providing the
-  /// ASTContext and the file ID of the primary file.
-  virtual void Initialize(ASTContext &Context, unsigned MainFileID) {}
+  /// ASTContext.
+  virtual void Initialize(ASTContext &Context) {}
   
   /// HandleTopLevelDecl - Handle the specified top-level declaration.  This is
   ///  called by HandleTopLevelDeclaration to process every top-level Decl*.
index 0ad83f71f663fbf1f14d59090782699c4f3b72b3..59e88716df8e1e91923f323c53e5eb37782e6334 100644 (file)
@@ -217,8 +217,7 @@ public:
 
   /// EnterMainSourceFile - Enter the specified FileID as the main source file,
   /// which implicitly adds the builtin defines etc.
-  void EnterMainSourceFile(unsigned CurFileID);
-  
+  void EnterMainSourceFile();  
   
   /// EnterSourceFile - Add a source file to the top of the include stack and
   /// start lexing tokens from it instead of the current buffer.  If isMainFile
index bffc4db9939e1944564711949006978ff5ebdb2d..5e9b65996f4f72f26ceae838fdf3192de71abb40 100644 (file)
@@ -23,8 +23,7 @@ namespace clang {
   /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
   /// the file is parsed.  This takes ownership of the ASTConsumer and
   /// ultimately deletes it.
-  void ParseAST(Preprocessor &pp, unsigned MainFileID, 
-                ASTConsumer *C, bool PrintStats = false);
+  void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false);
 }  // end namespace clang
 
 #endif