aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Driver/ASTConsumers.cpp6
-rw-r--r--Driver/CacheTokens.cpp4
-rw-r--r--Driver/DiagChecker.cpp6
-rw-r--r--Driver/HTMLPrint.cpp16
-rw-r--r--Driver/RewriteBlocks.cpp4
-rw-r--r--Driver/RewriteMacros.cpp2
-rw-r--r--Driver/RewriteObjC.cpp10
-rw-r--r--Driver/clang.cpp6
-rw-r--r--include/clang/Basic/SourceLocation.h60
-rw-r--r--include/clang/Basic/SourceManager.h82
-rw-r--r--include/clang/Lex/PTHLexer.h10
-rw-r--r--include/clang/Lex/PTHManager.h14
-rw-r--r--include/clang/Lex/Preprocessor.h6
-rw-r--r--include/clang/Lex/PreprocessorLexer.h22
-rw-r--r--include/clang/Lex/ScratchBuffer.h5
-rw-r--r--include/clang/Rewrite/HTMLRewrite.h20
-rw-r--r--include/clang/Rewrite/Rewriter.h13
-rw-r--r--include/clang/Rewrite/TokenRewriter.h2
-rw-r--r--lib/Basic/SourceLocation.cpp2
-rw-r--r--lib/Basic/SourceManager.cpp61
-rw-r--r--lib/Driver/HTMLDiagnostics.cpp92
-rw-r--r--lib/Driver/PlistDiagnostics.cpp29
-rw-r--r--lib/Lex/Lexer.cpp24
-rw-r--r--lib/Lex/PPDirectives.cpp12
-rw-r--r--lib/Lex/PPLexerChange.cpp15
-rw-r--r--lib/Lex/PTHLexer.cpp63
-rw-r--r--lib/Lex/Pragma.cpp10
-rw-r--r--lib/Lex/Preprocessor.cpp21
-rw-r--r--lib/Lex/PreprocessorLexer.cpp14
-rw-r--r--lib/Lex/ScratchBuffer.cpp6
-rw-r--r--lib/Lex/TokenLexer.cpp3
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp50
-rw-r--r--lib/Rewrite/Rewriter.cpp44
-rw-r--r--lib/Rewrite/TokenRewriter.cpp6
34 files changed, 403 insertions, 337 deletions
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp
index 9487a05072..6729746573 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -903,10 +903,10 @@ public:
return;
SourceManager& SourceMgr = TU.getContext().getSourceManager();
- unsigned ID = SourceMgr.getMainFileID();
- assert (ID && "MainFileID not set!");
+ FileID ID = SourceMgr.getMainFileID();
+ assert(!ID.isInvalid() && "MainFileID not set!");
const FileEntry* FE = SourceMgr.getFileEntryForID(ID);
- assert (FE && "No FileEntry for main file.");
+ assert(FE && "No FileEntry for main file.");
// FIXME: This is not portable to Windows.
// FIXME: This logic should probably be moved elsewhere later.
diff --git a/Driver/CacheTokens.cpp b/Driver/CacheTokens.cpp
index 4693b20bac..d447b90548 100644
--- a/Driver/CacheTokens.cpp
+++ b/Driver/CacheTokens.cpp
@@ -485,8 +485,8 @@ void PTHWriter::GeneratePTH() {
const llvm::MemoryBuffer *B = C.getBuffer();
if (!B) continue;
- unsigned FID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User);
- Lexer L(SourceLocation::getFileLoc(FID, 0), LOpts,
+ FileID FID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User);
+ Lexer L(SM.getLocForStartOfFile(FID), LOpts,
B->getBufferStart(), B->getBufferEnd(), B);
PM[FE] = LexTokens(L);
}
diff --git a/Driver/DiagChecker.cpp b/Driver/DiagChecker.cpp
index 8fa827ab19..6503214c52 100644
--- a/Driver/DiagChecker.cpp
+++ b/Driver/DiagChecker.cpp
@@ -117,12 +117,12 @@ static void FindExpectedDiags(Preprocessor &PP,
DiagList &ExpectedNotes) {
// Create a raw lexer to pull all the comments out of the main file. We don't
// want to look in #include'd headers for expected-error strings.
- unsigned FileID = PP.getSourceManager().getMainFileID();
+ FileID FID = PP.getSourceManager().getMainFileID();
std::pair<const char*,const char*> File =
- PP.getSourceManager().getBufferData(FileID);
+ PP.getSourceManager().getBufferData(FID);
// Create a lexer to lex all the tokens of the main file in raw mode.
- Lexer RawLex(SourceLocation::getFileLoc(FileID, 0),
+ Lexer RawLex(PP.getSourceManager().getLocForStartOfFile(FID),
PP.getLangOptions(), File.first, File.second);
// Return comments as tokens, this is how we find expected diagnostics.
diff --git a/Driver/HTMLPrint.cpp b/Driver/HTMLPrint.cpp
index 0956c2bca5..b2bb29c9eb 100644
--- a/Driver/HTMLPrint.cpp
+++ b/Driver/HTMLPrint.cpp
@@ -60,19 +60,19 @@ HTMLPrinter::~HTMLPrinter() {
return;
// Format the file.
- unsigned FileID = R.getSourceMgr().getMainFileID();
- const FileEntry* Entry = R.getSourceMgr().getFileEntryForID(FileID);
+ FileID FID = R.getSourceMgr().getMainFileID();
+ const FileEntry* Entry = R.getSourceMgr().getFileEntryForID(FID);
- html::AddLineNumbers(R, FileID);
- html::AddHeaderFooterInternalBuiltinCSS(R, FileID, Entry->getName());
+ html::AddLineNumbers(R, FID);
+ html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
// If we have a preprocessor, relex the file and syntax highlight.
// We might not have a preprocessor if we come from a deserialized AST file,
// for example.
- if (PP) html::SyntaxHighlight(R, FileID, *PP);
- if (PPF) html::HighlightMacros(R, FileID, *PP);
- html::EscapeText(R, FileID, false, true);
+ if (PP) html::SyntaxHighlight(R, FID, *PP);
+ if (PPF) html::HighlightMacros(R, FID, *PP);
+ html::EscapeText(R, FID, false, true);
// Open the output.
FILE *OutputFILE;
@@ -87,7 +87,7 @@ HTMLPrinter::~HTMLPrinter() {
}
// Emit the HTML.
- const RewriteBuffer &RewriteBuf = R.getEditBuffer(FileID);
+ const RewriteBuffer &RewriteBuf = R.getEditBuffer(FID);
char *Buffer = (char*)malloc(RewriteBuf.size());
std::copy(RewriteBuf.begin(), RewriteBuf.end(), Buffer);
fwrite(Buffer, 1, RewriteBuf.size(), OutputFILE);
diff --git a/Driver/RewriteBlocks.cpp b/Driver/RewriteBlocks.cpp
index e4e470a447..c729a904f6 100644
--- a/Driver/RewriteBlocks.cpp
+++ b/Driver/RewriteBlocks.cpp
@@ -37,7 +37,7 @@ class RewriteBlocks : public ASTConsumer {
ASTContext *Context;
SourceManager *SM;
- unsigned MainFileID;
+ FileID MainFileID;
const char *MainFileStart, *MainFileEnd;
// Block expressions.
@@ -223,7 +223,7 @@ void RewriteBlocks::Initialize(ASTContext &context) {
Preamble += "__OBJC_RW_EXTERN void *_NSConcreteStackBlock;\n";
Preamble += "#endif\n";
- InsertText(SourceLocation::getFileLoc(MainFileID, 0),
+ InsertText(SM->getLocForStartOfFile(MainFileID),
Preamble.c_str(), Preamble.size());
}
diff --git a/Driver/RewriteMacros.cpp b/Driver/RewriteMacros.cpp
index fb423c6413..ecf4b416d8 100644
--- a/Driver/RewriteMacros.cpp
+++ b/Driver/RewriteMacros.cpp
@@ -65,7 +65,7 @@ static void LexRawTokensFromMainFile(Preprocessor &PP,
// Create a lexer to lex all the tokens of the main file in raw mode. Even
// though it is in raw mode, it will not return comments.
- Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
+ Lexer RawLex(SM.getLocForStartOfFile(SM.getMainFileID()),
PP.getLangOptions(), File.first, File.second);
// Switch on comment lexing because we really do want them.
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp
index cee66f73b1..8af30f22e8 100644
--- a/Driver/RewriteObjC.cpp
+++ b/Driver/RewriteObjC.cpp
@@ -47,7 +47,7 @@ namespace {
ASTContext *Context;
SourceManager *SM;
TranslationUnitDecl *TUDecl;
- unsigned MainFileID;
+ FileID MainFileID;
const char *MainFileStart, *MainFileEnd;
SourceLocation LastIncLoc;
@@ -597,7 +597,7 @@ void RewriteObjC::HandleTopLevelDecl(Decl *D) {
//===----------------------------------------------------------------------===//
void RewriteObjC::RewriteInclude() {
- SourceLocation LocStart = SourceLocation::getFileLoc(MainFileID, 0);
+ SourceLocation LocStart = SM->getLocForStartOfFile(MainFileID);
std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
const char *MainBufStart = MainBuf.first;
const char *MainBufEnd = MainBuf.second;
@@ -645,8 +645,8 @@ void RewriteObjC::RewriteTabs() {
unsigned Spaces = 8-(VCol & 7);
// Get the location of the tab.
- SourceLocation TabLoc =
- SourceLocation::getFileLoc(MainFileID, BufPtr-MainBufStart);
+ SourceLocation TabLoc = SM->getLocForStartOfFile(MainFileID);
+ TabLoc = TabLoc.getFileLocWithOffset(BufPtr-MainBufStart);
// Rewrite the single tab character into a sequence of spaces.
ReplaceText(TabLoc, 1, " ", Spaces);
@@ -4501,7 +4501,7 @@ void RewriteObjC::HandleTranslationUnit(TranslationUnit& TU) {
RewriteInclude();
- InsertText(SourceLocation::getFileLoc(MainFileID, 0),
+ InsertText(SM->getLocForStartOfFile(MainFileID),
Preamble.c_str(), Preamble.size(), false);
if (ClassImplementation.size() || CategoryImplementation.size())
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index b7aea6799e..094d360dab 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -919,14 +919,14 @@ static bool InitializePreprocessor(Preprocessor &PP,
if (InFile != "-") {
const FileEntry *File = FileMgr.getFile(InFile);
if (File) SourceMgr.createMainFileID(File, SourceLocation());
- if (SourceMgr.getMainFileID() == 0) {
+ if (SourceMgr.getMainFileID().isInvalid()) {
fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
return true;
}
} else {
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
- if (SourceMgr.getMainFileID() == 0) {
+ if (SourceMgr.getMainFileID().isInvalid()) {
fprintf(stderr, "Error reading standard input! Empty?\n");
return true;
}
@@ -1335,7 +1335,7 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
std::pair<const char*,const char*> File =
SM.getBufferData(SM.getMainFileID());
// Start lexing the specified input file.
- Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
+ Lexer RawLex(SM.getLocForStartOfFile(SM.getMainFileID()),
PP.getLangOptions(), File.first, File.second);
RawLex.SetKeepWhitespaceMode(true);
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h
index ba359bddae..227313b7bf 100644
--- a/include/clang/Basic/SourceLocation.h
+++ b/include/clang/Basic/SourceLocation.h
@@ -18,13 +18,46 @@
#include "llvm/Bitcode/SerializationFwd.h"
namespace llvm {
-class MemoryBuffer;
+ class MemoryBuffer;
+ template <typename T> struct DenseMapInfo;
}
namespace clang {
class SourceManager;
class FileEntry;
+
+/// FileID - This is an opaque identifier used by SourceManager which refers to
+/// a source file (MemoryBuffer) along with its #include path and #line data.
+///
+class FileID {
+ /// ID - Opaque identifier, 0 is "invalid".
+ unsigned ID;
+public:
+ FileID() : ID(0) {}
+
+ bool isInvalid() const { return ID == 0; }
+
+ bool operator==(const FileID &RHS) const { return ID == RHS.ID; }
+ bool operator<(const FileID &RHS) const { return ID < RHS.ID; }
+ bool operator<=(const FileID &RHS) const { return ID <= RHS.ID; }
+ bool operator!=(const FileID &RHS) const { return !(*this == RHS); }
+ bool operator>(const FileID &RHS) const { return RHS < *this; }
+ bool operator>=(const FileID &RHS) const { return RHS <= *this; }
+
+ static FileID getSentinel() { return Create(~0U); }
+ unsigned getHashValue() const { return ID; }
+
+private:
+ friend class SourceManager;
+ static FileID Create(unsigned V) {
+ FileID F;
+ F.ID = V;
+ return F;
+ }
+ unsigned getOpaqueValue() const { return ID; }
+};
+
/// SourceLocation - This is a carefully crafted 32-bit identifier that encodes
/// a full include stack, line and column number information for a position in
@@ -269,4 +302,29 @@ public:
} // end namespace clang
+namespace llvm {
+ /// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
+ /// DenseSets.
+ template <>
+ struct DenseMapInfo<clang::FileID> {
+ static inline clang::FileID getEmptyKey() {
+ return clang::FileID();
+ }
+ static inline clang::FileID getTombstoneKey() {
+ return clang::FileID::getSentinel();
+ }
+
+ static unsigned getHashValue(clang::FileID S) {
+ return S.getHashValue();
+ }
+
+ static bool isEqual(clang::FileID LHS, clang::FileID RHS) {
+ return LHS == RHS;
+ }
+
+ static bool isPod() { return true; }
+ };
+
+} // end namespace llvm
+
#endif
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 4db38017cc..4f46bad8db 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -256,47 +256,47 @@ class SourceManager {
/// LastLineNo - These ivars serve as a cache used in the getLineNumber
/// method which is used to speedup getLineNumber calls to nearby locations.
- mutable unsigned LastLineNoFileIDQuery;
+ mutable FileID LastLineNoFileIDQuery;
mutable SrcMgr::ContentCache *LastLineNoContentCache;
mutable unsigned LastLineNoFilePos;
mutable unsigned LastLineNoResult;
/// MainFileID - The file ID for the main source file of the translation unit.
- unsigned MainFileID;
+ FileID MainFileID;
// SourceManager doesn't support copy construction.
explicit SourceManager(const SourceManager&);
void operator=(const SourceManager&);
public:
- SourceManager() : LastLineNoFileIDQuery(~0U), MainFileID(0) {}
+ SourceManager() {}
~SourceManager() {}
void clearIDTables() {
- MainFileID = 0;
+ MainFileID = FileID();
FileIDs.clear();
MacroIDs.clear();
- LastLineNoFileIDQuery = ~0U;
+ LastLineNoFileIDQuery = FileID();
LastLineNoContentCache = 0;
}
/// getMainFileID - Returns the FileID of the main source file.
- unsigned getMainFileID() const { return MainFileID; }
+ FileID getMainFileID() const { return MainFileID; }
/// createFileID - Create a new FileID that represents the specified file
/// being #included from the specified IncludePosition. This returns 0 on
/// error and translates NULL into standard input.
- unsigned createFileID(const FileEntry *SourceFile, SourceLocation IncludePos,
+ FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos,
SrcMgr::CharacteristicKind FileCharacter) {
const SrcMgr::ContentCache *IR = getContentCache(SourceFile);
- if (IR == 0) return 0; // Error opening file?
+ if (IR == 0) return FileID(); // Error opening file?
return createFileID(IR, IncludePos, FileCharacter);
}
/// createMainFileID - Create the FileID for the main source file.
- unsigned createMainFileID(const FileEntry *SourceFile,
+ FileID createMainFileID(const FileEntry *SourceFile,
SourceLocation IncludePos) {
- assert (MainFileID == 0 && "MainFileID already set!");
+ assert(MainFileID.isInvalid() && "MainFileID already set!");
MainFileID = createFileID(SourceFile, IncludePos, SrcMgr::C_User);
return MainFileID;
}
@@ -304,7 +304,7 @@ public:
/// createFileIDForMemBuffer - Create a new FileID that represents the
/// specified memory buffer. This does no caching of the buffer and takes
/// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once.
- unsigned createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
+ FileID createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
return createFileID(createMemBufferContentCache(Buffer), SourceLocation(),
SrcMgr::C_User);
}
@@ -312,12 +312,19 @@ public:
/// createMainFileIDForMembuffer - Create the FileID for a memory buffer
/// that will represent the FileID for the main source. One example
/// of when this would be used is when the main source is read from STDIN.
- unsigned createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
- assert (MainFileID == 0 && "MainFileID already set!");
+ FileID createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
+ assert(MainFileID.isInvalid() && "MainFileID already set!");
MainFileID = createFileIDForMemBuffer(Buffer);
return MainFileID;
}
+ /// getLocForStartOfFile - Return the source location corresponding to the
+ /// first byte of the specified file.
+ SourceLocation getLocForStartOfFile(FileID FID) const {
+ return SourceLocation::getFileLoc(FID.ID, 0);
+ }
+
+
/// getInstantiationLoc - Return a new SourceLocation that encodes the fact
/// that a token at Loc should actually be referenced from InstantiationLoc.
SourceLocation getInstantiationLoc(SourceLocation Loc,
@@ -325,13 +332,19 @@ public:
/// getBuffer - Return the buffer for the specified FileID.
///
- const llvm::MemoryBuffer *getBuffer(unsigned FileID) const {
- return getContentCache(FileID)->getBuffer();
+ const llvm::MemoryBuffer *getBuffer(FileID FID) const {
+ return getContentCache(FID)->getBuffer();
+ }
+
+ const llvm::MemoryBuffer *getBuffer(SourceLocation Loc) const {
+ return getContentCacheForLoc(Loc)->getBuffer();
}
+
/// getBufferData - Return a pointer to the start and end of the character
/// data for the specified FileID.
- std::pair<const char*, const char*> getBufferData(unsigned FileID) const;
+ std::pair<const char*, const char*> getBufferData(SourceLocation Loc) const;
+ std::pair<const char*, const char*> getBufferData(FileID FID) const;
/// getIncludeLoc - Return the location of the #include for the specified
/// SourceLocation. If this is a macro expansion, this transparently figures
@@ -414,8 +427,8 @@ public:
}
/// getFileEntryForID - Returns the FileEntry record for the provided FileID.
- const FileEntry* getFileEntryForID(unsigned id) const {
- return getContentCache(id)->Entry;
+ const FileEntry *getFileEntryForID(FileID FID) const {
+ return getContentCache(FID)->Entry;
}
/// getCanonicalFileID - Return the canonical FileID for a SourceLocation.
@@ -423,14 +436,14 @@ public:
/// into multiple chunks. This method returns the unique FileID without
/// chunk information for a given SourceLocation. Use this method when
/// you want to compare FileIDs across SourceLocations.
- unsigned getCanonicalFileID(SourceLocation SpellingLoc) const {
+ FileID getCanonicalFileID(SourceLocation SpellingLoc) const {
return getDecomposedFileLoc(SpellingLoc).first;
}
/// getDecomposedFileLoc - Decompose the specified file location into a raw
/// FileID + Offset pair. The first element is the FileID, the second is the
/// offset from the start of the buffer of the location.
- std::pair<unsigned, unsigned> getDecomposedFileLoc(SourceLocation Loc) const {
+ std::pair<FileID, unsigned> getDecomposedFileLoc(SourceLocation Loc) const {
assert(Loc.isFileID() && "Isn't a File SourceLocation");
// TODO: Add a flag "is first chunk" to SLOC.
@@ -444,7 +457,7 @@ public:
assert(Loc.getFileID() >= ChunkNo && "Unexpected offset");
- return std::make_pair(Loc.getFileID()-ChunkNo, Offset);
+ return std::make_pair(FileID::Create(Loc.getFileID()-ChunkNo), Offset);
}
/// getFullFilePos - This (efficient) method returns the offset from the start
@@ -474,8 +487,8 @@ public:
SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const {
return getFIDInfo(getSpellingLoc(Loc).getFileID())->getFileCharacteristic();
}
- SrcMgr::CharacteristicKind getFileCharacteristic(unsigned FileID) const {
- return getFIDInfo(FileID)->getFileCharacteristic();
+ SrcMgr::CharacteristicKind getFileCharacteristic(FileID FID) const {
+ return getFIDInfo(FID)->getFileCharacteristic();
}
// Iterators over FileInfos.
@@ -500,26 +513,29 @@ private:
/// createFileID - Create a new fileID for the specified ContentCache and
/// include position. This works regardless of whether the ContentCache
/// corresponds to a file or some other input source.
- unsigned createFileID(const SrcMgr::ContentCache* File,
- SourceLocation IncludePos,
- SrcMgr::CharacteristicKind DirCharacter);
+ FileID createFileID(const SrcMgr::ContentCache* File,
+ SourceLocation IncludePos,
+ SrcMgr::CharacteristicKind DirCharacter);
/// getContentCache - Create or return a cached ContentCache for the specified
/// file. This returns null on failure.
- const SrcMgr::ContentCache* getContentCache(const FileEntry* SourceFile);
+ const SrcMgr::ContentCache* getContentCache(const FileEntry *SourceFile);
/// createMemBufferContentCache - Create a new ContentCache for the specified
/// memory buffer.
const SrcMgr::ContentCache*
- createMemBufferContentCache(const llvm::MemoryBuffer* Buf);
+ createMemBufferContentCache(const llvm::MemoryBuffer *Buf);
- const SrcMgr::FileIDInfo* getFIDInfo(unsigned FileID) const {
- assert(FileID-1 < FileIDs.size() && "Invalid FileID!");
- return &FileIDs[FileID-1];
+ const SrcMgr::FileIDInfo *getFIDInfo(unsigned FID) const {
+ assert(FID-1 < FileIDs.size() && "Invalid FileID!");
+ return &FileIDs[FID-1];
+ }
+ const SrcMgr::FileIDInfo *getFIDInfo(FileID FID) const {
+ return getFIDInfo(FID.ID);
}
- const SrcMgr::ContentCache *getContentCache(unsigned FileID) const {
- return getContentCache(getFIDInfo(FileID));
+ const SrcMgr::ContentCache *getContentCache(FileID FID) const {
+ return getContentCache(getFIDInfo(FID.ID));
}
/// Return the ContentCache structure for the specified FileID.
diff --git a/include/clang/Lex/PTHLexer.h b/include/clang/Lex/PTHLexer.h
index f19d67958f..e58c5e3f2b 100644
--- a/include/clang/Lex/PTHLexer.h
+++ b/include/clang/Lex/PTHLexer.h
@@ -23,9 +23,7 @@ class PTHManager;
class PTHSpellingSearch;
class PTHLexer : public PreprocessorLexer {
-private:
- /// FileID - The SourceManager FileID for the original source file.
- unsigned FileID;
+ SourceLocation FileStartLoc;
/// TokBuf - Buffer from PTH file containing raw token data.
const char* TokBuf;
@@ -66,10 +64,8 @@ protected:
friend class PTHManager;
/// Create a PTHLexer for the specified token stream.
- PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D,
- const char* ppcond,
- PTHSpellingSearch& mySpellingSrch,
- PTHManager& PM);
+ PTHLexer(Preprocessor& pp, FileID FID, const char *D, const char* ppcond,
+ PTHSpellingSearch& mySpellingSrch, PTHManager &PM);
public:
~PTHLexer() {}
diff --git a/include/clang/Lex/PTHManager.h b/include/clang/Lex/PTHManager.h
index 634c088b8f..c4ecfd6ed1 100644
--- a/include/clang/Lex/PTHManager.h
+++ b/include/clang/Lex/PTHManager.h
@@ -62,7 +62,7 @@ class PTHManager : public IdentifierInfoLookup {
const llvm::MemoryBuffer* Buf;
/// A map from FileIDs to SpellingSearch objects.
- llvm::DenseMap<unsigned,PTHSpellingSearch*> SpellingMap;
+ llvm::DenseMap<FileID, PTHSpellingSearch*> SpellingMap;
/// Alloc - Allocator used for IdentifierInfo objects.
llvm::BumpPtrAllocator Alloc;
@@ -117,20 +117,22 @@ public:
/// Unlike the version in IdentifierTable, this returns a pointer instead
/// of a reference. If the pointer is NULL then the IdentifierInfo cannot
/// be found.
- IdentifierInfo* get(const char *NameStart, const char *NameEnd);
+ IdentifierInfo *get(const char *NameStart, const char *NameEnd);
/// Create - This method creates PTHManager objects. The 'file' argument
/// is the name of the PTH file. This method returns NULL upon failure.
- static PTHManager* Create(const std::string& file);
+ static PTHManager *Create(const std::string& file);
- void setPreprocessor(Preprocessor* pp) { PP = pp; }
+ void setPreprocessor(Preprocessor *pp) { PP = pp; }
/// CreateLexer - Return a PTHLexer that "lexes" the cached tokens for the
/// specified file. This method returns NULL if no cached tokens exist.
/// It is the responsibility of the caller to 'delete' the returned object.
- PTHLexer* CreateLexer(unsigned FileID, const FileEntry* FE);
+ PTHLexer *CreateLexer(FileID FID, const FileEntry *FE);
- unsigned getSpelling(unsigned FileID, unsigned fpos, const char *& Buffer);
+ unsigned getSpelling(SourceLocation Loc, const char *&Buffer);
+private:
+ unsigned getSpelling(FileID FID, unsigned fpos, const char *& Buffer);
};
} // end namespace clang
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index b85c725490..e453fd04d6 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -284,7 +284,7 @@ public:
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer. If isMainFile
/// is true, this is the main file for the translation unit.
- void EnterSourceFile(unsigned CurFileID, const DirectoryLookup *Dir);
+ void EnterSourceFile(FileID CurFileID, const DirectoryLookup *Dir);
/// EnterMacro - Add a Macro to the top of the include stack and start lexing
/// tokens from it instead of the current buffer. Args specifies the
@@ -456,10 +456,8 @@ public:
char getSpelledCharacterAt(SourceLocation SL) const {
if (PTH) {
SL = SourceMgr.getSpellingLoc(SL);
- unsigned FID = SourceMgr.getCanonicalFileID(SL);
- unsigned FPos = SourceMgr.getFullFilePos(SL);
const char *Data;
- if (PTH->getSpelling(FID, FPos, Data))
+ if (PTH->getSpelling(SL, Data))
return *Data;
}
diff --git a/include/clang/Lex/PreprocessorLexer.h b/include/clang/Lex/PreprocessorLexer.h
index a889a55b52..3cf0f92b30 100644
--- a/include/clang/Lex/PreprocessorLexer.h
+++ b/include/clang/Lex/PreprocessorLexer.h
@@ -27,8 +27,8 @@ class PreprocessorLexer {
protected:
Preprocessor *PP; // Preprocessor object controlling lexing.
- /// The SourceManager fileID corresponding to the file being lexed.
- const unsigned FileID;
+ /// The SourceManager FileID corresponding to the file being lexed.
+ const FileID FID;
//===--------------------------------------------------------------------===//
// Context-specific lexing flags set by the preprocessor.
@@ -67,15 +67,17 @@ protected:
void operator=(const PreprocessorLexer&); // DO NOT IMPLEMENT
friend class Preprocessor;
- PreprocessorLexer(Preprocessor* pp, SourceLocation L);
-
+ PreprocessorLexer(Preprocessor *pp, FileID fid)
+ : PP(pp), FID(fid), ParsingPreprocessorDirective(false),
+ ParsingFilename(false), LexingRawMode(false) {}
+
PreprocessorLexer()
- : PP(0), FileID(0),
+ : PP(0),
ParsingPreprocessorDirective(false),
ParsingFilename(false),
LexingRawMode(false) {}
- virtual ~PreprocessorLexer();
+ virtual ~PreprocessorLexer() {}
virtual void IndirectLex(Token& Result) = 0;
@@ -143,11 +145,15 @@ public:
/// getPP - Return the preprocessor object for this lexer.
Preprocessor *getPP() const { return PP; }
- unsigned getFileID() const {
+ FileID getFileID() const {
assert(PP &&
"PreprocessorLexer::getFileID() should only be used with a Preprocessor");
- return FileID;
+ return FID;
}
+
+ /// getFileEntry - Return the FileEntry corresponding to this FileID. Like
+ /// getFileID(), this only works for lexers with attached preprocessors.
+ const FileEntry *getFileEntry() const;
};
} // end namespace clang
diff --git a/include/clang/Lex/ScratchBuffer.h b/include/clang/Lex/ScratchBuffer.h
index c1d134de11..eec6a251a5 100644
--- a/include/clang/Lex/ScratchBuffer.h
+++ b/include/clang/Lex/ScratchBuffer.h
@@ -14,9 +14,10 @@
#ifndef LLVM_CLANG_SCRATCHBUFFER_H
#define LLVM_CLANG_SCRATCHBUFFER_H
+#include "clang/Basic/SourceLocation.h"
+
namespace clang {
class SourceManager;
- class SourceLocation;
/// ScratchBuffer - This class exposes a simple interface for the dynamic
/// construction of tokens. This is used for builtin macros (e.g. __LINE__) as
@@ -24,7 +25,7 @@ namespace clang {
class ScratchBuffer {
SourceManager &SourceMgr;
char *CurBuffer;
- unsigned FileID;
+ SourceLocation BufferStartLoc;
unsigned BytesUsed;
public:
ScratchBuffer(SourceManager &SM);
diff --git a/include/clang/Rewrite/HTMLRewrite.h b/include/clang/Rewrite/HTMLRewrite.h
index bbb7f3490b..2f5696606e 100644
--- a/include/clang/Rewrite/HTMLRewrite.h
+++ b/include/clang/Rewrite/HTMLRewrite.h
@@ -51,7 +51,7 @@ namespace html {
/// EscapeText - HTMLize a specified file so that special characters are
/// are translated so that they are not interpreted as HTML tags.
- void EscapeText(Rewriter& R, unsigned FileID,
+ void EscapeText(Rewriter& R, FileID FID,
bool EscapeSpaces = false, bool ReplacesTabs = true);
/// EscapeText - HTMLized the provided string so that special characters
@@ -61,29 +61,21 @@ namespace html {