[cfe-commits] r62401 - in /cfe/trunk: Driver/CacheTokens.cpp include/clang/Basic/SourceManager.h lib/Lex/Lexer.cpp
Chris Lattner
sabre at nondot.org
Fri Jan 16 19:48:08 PST 2009
Author: lattner
Date: Fri Jan 16 21:48:08 2009
New Revision: 62401
URL: http://llvm.org/viewvc/llvm-project?rev=62401&view=rev
Log:
Instead of iterating over FileID's, have PTH generation iterate over the
content cache directly. Content cache has a 1-1 mapping with fileentries,
whereas multiple FileIDs can be the same FileEntry.
Modified:
cfe/trunk/Driver/CacheTokens.cpp
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Lex/Lexer.cpp
Modified: cfe/trunk/Driver/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/CacheTokens.cpp?rev=62401&r1=62400&r2=62401&view=diff
==============================================================================
--- cfe/trunk/Driver/CacheTokens.cpp (original)
+++ cfe/trunk/Driver/CacheTokens.cpp Fri Jan 16 21:48:08 2009
@@ -467,17 +467,13 @@
void PTHWriter::GeneratePTH() {
// Iterate over all the files in SourceManager. Create a lexer
// for each file and cache the tokens.
- SourceManager& SM = PP.getSourceManager();
- const LangOptions& LOpts = 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 @@
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);
}
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=62401&r1=62400&r2=62401&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Fri Jan 16 21:48:08 2009
@@ -478,31 +478,11 @@
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;
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=62401&r1=62400&r2=62401&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Jan 16 21:48:08 2009
@@ -112,8 +112,7 @@
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();
More information about the cfe-commits
mailing list