]> granicus.if.org Git - clang/commitdiff
Instead of iterating over FileID's, have PTH generation iterate over the
authorChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 03:48:08 +0000 (03:48 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 03:48:08 +0000 (03:48 +0000)
content cache directly.  Content cache has a 1-1 mapping with fileentries,
whereas multiple FileIDs can be the same FileEntry.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62401 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/CacheTokens.cpp
include/clang/Basic/SourceManager.h
lib/Lex/Lexer.cpp

index d791e09d6c2a98f6d8cd024be30bdcfb54e65929..33986f8254983b81008a2bedb50c905b1d045c2f 100644 (file)
@@ -467,17 +467,13 @@ void PTHWriter::EmitCachedSpellings() {
 void PTHWriter::GeneratePTH() {
   // Iterate over all the files in SourceManager.  Create a lexer
   // for each file and cache the tokens.
-  SourceManagerSM = PP.getSourceManager();
-  const LangOptionsLOpts = PP.getLangOptions();
+  SourceManager &SM = PP.getSourceManager();
+  const LangOptions &LOpts = PP.getLangOptions();
   
-  for (SourceManager::fileid_iterator I=SM.fileid_begin(), E=SM.fileid_end();
-       I!=E; ++I) {
-    
-    const SrcMgr::ContentCache* C = I.getFileIDInfo().getContentCache();
-    if (!C) continue;
-
-    const FileEntry* FE = C->Entry;    // Does this entry correspond to a file?    
-    if (!FE) continue;
+  for (SourceManager::fileinfo_iterator I = SM.fileinfo_begin(),
+       E = SM.fileinfo_end(); I != E; ++I) {
+    const SrcMgr::ContentCache &C = *I;
+    const FileEntry *FE = C.Entry;
     
     // FIXME: Handle files with non-absolute paths.
     llvm::sys::Path P(FE->getName());
@@ -487,12 +483,12 @@ void PTHWriter::GeneratePTH() {
     PCHMap::iterator PI = PM.find(FE); // Have we already processed this file?
     if (PI != PM.end()) continue;
     
-    const llvm::MemoryBuffer* B = C->getBuffer();
+    const llvm::MemoryBuffer *B = C.getBuffer();
     if (!B) continue;
-    
-    Lexer L(SourceLocation::getFileLoc(I.getFileID(), 0), LOpts,
-            B->getBufferStart(), B->getBufferEnd(), B);
 
+    unsigned FID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User);
+    Lexer L(SourceLocation::getFileLoc(FID, 0), LOpts,
+            B->getBufferStart(), B->getBufferEnd(), B);
     PM[FE] = LexTokens(L);
   }
 
index 1eac4f15ded09a1964b39f88b2359a24f9c0ba00..9a67627485c6069ed19eb503c8fa434cb42a7d4b 100644 (file)
@@ -478,31 +478,11 @@ public:
     return getFIDInfo(FileID)->getFileCharacteristic();
   }
   
-  // Iterators over FileIDs.
-  
-  class fileid_iterator {
-    std::vector<SrcMgr::FileIDInfo>::iterator I;
-    unsigned fid;
-  public:
-    fileid_iterator(std::vector<SrcMgr::FileIDInfo>::iterator i, unsigned f)
-      : I(i), fid(f) {}
-    
-    bool operator==(const fileid_iterator& X) const { return X.fid == fid; }
-    bool operator!=(const fileid_iterator& X) const { return X.fid != fid; }
-    fileid_iterator& operator++() { ++fid; ++I; return *this; }
-    
-    unsigned getFileID() const { return fid; }
-    SrcMgr::FileIDInfo& getFileIDInfo() { return *I; }
-  };
-  
-  fileid_iterator fileid_begin() {
-    return fileid_iterator(FileIDs.begin(), 1);
-  }
-  
-  fileid_iterator fileid_end() {
-    return fileid_iterator(FileIDs.end(), FileIDs.size()+1);
-  }
-  
+  // Iterators over FileInfos.
+  typedef std::set<SrcMgr::ContentCache>::const_iterator fileinfo_iterator;
+  fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); }
+  fileinfo_iterator fileinfo_end() const { return FileInfos.end(); }
+
   /// PrintStats - Print statistics to stderr.
   ///
   void PrintStats() const;
index fa29d0a38e09dc712f22aa06acd12464de1262ff..5a14c1356a0452a0c620eb94bff3567b4e8f0299 100644 (file)
@@ -112,8 +112,7 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &pp,
 Lexer::Lexer(SourceLocation fileloc, const LangOptions &features,
              const char *BufStart, const char *BufEnd,
              const llvm::MemoryBuffer *FromFile)
-  : PreprocessorLexer(), FileLoc(fileloc),
-    Features(features) {
+  : FileLoc(fileloc), Features(features) {
       
   Is_PragmaLexer = false;
   InitCharacterInfo();