summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-01-17 03:48:08 +0000
committerChris Lattner <sabre@nondot.org>2009-01-17 03:48:08 +0000
commit1abd20901b4a52e0c450e8f2ef2efba9affadac3 (patch)
treea13b6dbfbf224ec98aa37f4744df1e6f17fd5ea8
parent3feddd91f74e09b998100093dc4931ba80894600 (diff)
downloadbcm5719-llvm-1abd20901b4a52e0c450e8f2ef2efba9affadac3.tar.gz
bcm5719-llvm-1abd20901b4a52e0c450e8f2ef2efba9affadac3.zip
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. llvm-svn: 62401
-rw-r--r--clang/Driver/CacheTokens.cpp24
-rw-r--r--clang/include/clang/Basic/SourceManager.h30
-rw-r--r--clang/lib/Lex/Lexer.cpp3
3 files changed, 16 insertions, 41 deletions
diff --git a/clang/Driver/CacheTokens.cpp b/clang/Driver/CacheTokens.cpp
index d791e09d6c2..33986f82549 100644
--- a/clang/Driver/CacheTokens.cpp
+++ b/clang/Driver/CacheTokens.cpp
@@ -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.
- 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 @@ 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);
}
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 1eac4f15ded..9a67627485c 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -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;
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index fa29d0a38e0..5a14c1356a0 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -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();
OpenPOWER on IntegriCloud