]> granicus.if.org Git - clang/commitdiff
Use a common SourceManager when processing multiple files. This allows us to cache...
authorTed Kremenek <kremenek@apple.com>
Fri, 6 Jun 2008 22:42:39 +0000 (22:42 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 6 Jun 2008 22:42:39 +0000 (22:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52066 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/clang.cpp
include/clang/Basic/SourceManager.h

index 5eec67ca87921d52337843239c60efd25be2b445..6f7e1a256b1450ea7b0726bb6f1b1857bb178b66 100644 (file)
@@ -1459,6 +1459,8 @@ int main(int argc, char **argv) {
     exit(1);
   }
   
+  llvm::OwningPtr<SourceManager> SourceMgr;
+  
   for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
     const std::string &InFile = InputFilenames[i];
     
@@ -1467,7 +1469,10 @@ int main(int argc, char **argv) {
     else {            
       /// Create a SourceManager object.  This tracks and owns all the file
       /// buffers allocated to a translation unit.
-      SourceManager SourceMgr;
+      if (!SourceMgr)
+        SourceMgr.reset(new SourceManager());
+      else
+        SourceMgr->clearIDTables();
       
       // Initialize language options, inferring file types from input filenames.
       LangOptions LangInfo;
@@ -1490,7 +1495,7 @@ int main(int argc, char **argv) {
       
       // Set up the preprocessor with these options.
       DriverPreprocessorFactory PPFactory(InFile, Diags, LangInfo, *Target,
-                                          SourceMgr, HeaderInfo);
+                                          *SourceMgr.get(), HeaderInfo);
       
       llvm::OwningPtr<Preprocessor> PP(PPFactory.CreatePreprocessor());
             
@@ -1498,13 +1503,14 @@ int main(int argc, char **argv) {
         continue;
       
       ProcessInputFile(*PP, PPFactory, InFile);
-      HeaderInfo.ClearFileInfo();
+      HeaderInfo.ClearFileInfo();      
       
       if (Stats)
-        SourceMgr.PrintStats();
+        SourceMgr->PrintStats();
     }
   }
   
+  
   delete Target;
 
   unsigned NumDiagnostics = Diags.getNumDiagnostics();
index 700dcd31acc421c46cbc4f27cabb434774e62da1..e5ebbf9dffe00fd780dd7a74b69e77cf17597414 100644 (file)
@@ -231,6 +231,7 @@ public:
   ~SourceManager() {}
   
   void clearIDTables() {
+    MainFileID = 0;
     FileIDs.clear();
     MacroIDs.clear();
     LastLineNoFileIDQuery = ~0U;