[cfe-commits] r67886 - in /cfe/trunk: include/clang/Basic/FileManager.h tools/clang-cc/CacheTokens.cpp

Chris Lattner sabre at nondot.org
Fri Mar 27 17:55:35 PDT 2009


Author: lattner
Date: Fri Mar 27 19:55:35 2009
New Revision: 67886

URL: http://llvm.org/viewvc/llvm-project?rev=67886&view=rev
Log:
move StatListener out to top level.

Modified:
    cfe/trunk/include/clang/Basic/FileManager.h
    cfe/trunk/tools/clang-cc/CacheTokens.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=67886&r1=67885&r2=67886&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Fri Mar 27 19:55:35 2009
@@ -126,7 +126,9 @@
   /// setStatCache - Installs the provided StatSysCallCache object within
   ///  the FileManager.  Ownership of this object is transferred to the
   ///  FileManager.
-  void setStatCache(StatSysCallCache *statCache) { StatCache.reset(statCache); }
+  void setStatCache(StatSysCallCache *statCache) {
+    StatCache.reset(statCache);
+  }
   
   /// getDirectory - Lookup, cache, and verify the specified directory.  This
   /// returns null if the directory doesn't exist.

Modified: cfe/trunk/tools/clang-cc/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/CacheTokens.cpp?rev=67886&r1=67885&r2=67886&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/CacheTokens.cpp (original)
+++ cfe/trunk/tools/clang-cc/CacheTokens.cpp Fri Mar 27 19:55:35 2009
@@ -375,43 +375,12 @@
   PTHEntry LexTokens(Lexer& L);
   Offset EmitCachedSpellings();
 
-  /// StatListener - A simple "interpose" object used to monitor stat calls
-  /// invoked by FileManager while processing the original sources used
-  /// as input to PTH generation.  StatListener populates the PTHWriter's
-  /// file map with stat information for directories as well as negative stats.
-  /// Stat information for files are populated elsewhere.
-  class StatListener : public StatSysCallCache {
-    PTHMap& PM;
-  public:
-    StatListener(PTHMap& pm) : PM(pm) {}
-    ~StatListener() {}
-    
-    int stat(const char *path, struct stat *buf) {
-      int result = ::stat(path, buf);
-      
-      if (result != 0) // Failed 'stat'.
-        PM.insert(path, PTHEntry());
-      else if (S_ISDIR(buf->st_mode)) {
-        // Only cache directories with absolute paths.
-        if (!llvm::sys::Path(path).isAbsolute())
-          return result;
-
-        PM.insert(PTHEntryKeyVariant(buf, path), PTHEntry());
-      }
-        
-      return result;
-    }
-  };
-  
 public:
   PTHWriter(llvm::raw_fd_ostream& out, Preprocessor& pp) 
     : Out(out), PP(pp), idcount(0), CurStrOffset(0) {}
     
+  PTHMap &getPM() { return PM; }
   void GeneratePTH(const std::string *MainFile = 0);
-
-  StatSysCallCache *createStatListener() {
-    return new StatListener(PM);
-  }
 };
 } // end anonymous namespace
   
@@ -687,6 +656,37 @@
   Emit32(SpellingOff);
 }
 
+namespace {
+/// StatListener - A simple "interpose" object used to monitor stat calls
+/// invoked by FileManager while processing the original sources used
+/// as input to PTH generation.  StatListener populates the PTHWriter's
+/// file map with stat information for directories as well as negative stats.
+/// Stat information for files are populated elsewhere.
+class StatListener : public StatSysCallCache {
+  PTHMap ±
+public:
+  StatListener(PTHMap &pm) : PM(pm) {}
+  ~StatListener() {}
+  
+  int stat(const char *path, struct stat *buf) {
+    int result = ::stat(path, buf);
+    
+    if (result != 0) // Failed 'stat'.
+      PM.insert(path, PTHEntry());
+    else if (S_ISDIR(buf->st_mode)) {
+      // Only cache directories with absolute paths.
+      if (!llvm::sys::Path(path).isAbsolute())
+        return result;
+      
+      PM.insert(PTHEntryKeyVariant(buf, path), PTHEntry());
+    }
+    
+    return result;
+  }
+};
+} // end anonymous namespace
+
+
 void clang::CacheTokens(Preprocessor &PP, const std::string &OutFile) {
   // Open up the PTH file.
   std::string ErrMsg;
@@ -715,7 +715,7 @@
   PTHWriter PW(Out, PP);
   
   // Install the 'stat' system call listener in the FileManager.
-  PP.getFileManager().setStatCache(PW.createStatListener());
+  PP.getFileManager().setStatCache(new StatListener(PW.getPM()));
   
   // Lex through the entire file.  This will populate SourceManager with
   // all of the header information.





More information about the cfe-commits mailing list