- Added method "setPTHManager" that will be called by the driver to install
  a PTHManager for the Preprocessor.
- Fixed some comments.
- Added EnterSourceFileWithPTH to mirror EnterSourceFileWithLexer.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60437 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2008-12-02 19:46:31 +00:00
Родитель be1ee79d20
Коммит 6137dc99ef
2 изменённых файлов: 44 добавлений и 4 удалений

Просмотреть файл

@ -18,6 +18,7 @@
#include "clang/Lex/PTHLexer.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/TokenLexer.h"
#include "clang/Lex/PTHManager.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
@ -51,6 +52,10 @@ class Preprocessor {
ScratchBuffer *ScratchBuf;
HeaderSearch &HeaderInfo;
/// PTH - An optional PTHManager object used for getting tokens from
/// a token cache rather than lexing the original source file.
llvm::OwningPtr<PTHManager> PTH;
/// Identifiers for builtin macros and other builtins.
IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
@ -190,6 +195,8 @@ public:
IdentifierTable &getIdentifierTable() { return Identifiers; }
SelectorTable &getSelectorTable() { return Selectors; }
void setPTHManager(PTHManager* pm) { PTH.reset(pm); }
/// SetCommentRetentionState - Control whether or not the preprocessor retains
/// comments in output.
void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments) {
@ -591,11 +598,14 @@ private:
/// been read into 'Tok'.
void Handle_Pragma(Token &Tok);
/// EnterSourceFileWithLexer - Add a lexer to the top of the include stack and
/// start lexing tokens from it instead of the current buffer.
void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir);
/// EnterSourceFileWithPTH - Add a lexer to the top of the include stack and
/// start getting tokens from it using the PTH cache.
void EnterSourceFileWithPTH(PTHLexer *PL, const DirectoryLookup *Dir);
/// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully
/// checked and spelled filename, e.g. as an operand of #include. This returns
/// true if the input filename was in <>'s or false if it were in ""'s. The

Просмотреть файл

@ -75,6 +75,16 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
MaxIncludeStackDepth = IncludeMacroStack.size();
#if 1
if (PTH) {
PTHLexer* PL =
PTH->CreateLexer(FileID, getSourceManager().getFileEntryForID(FileID));
if (PL) {
EnterSourceFileWithPTH(PL, CurDir);
return;
}
}
Lexer *TheLexer = new Lexer(SourceLocation::getFileLoc(FileID, 0), *this);
EnterSourceFileWithLexer(TheLexer, CurDir);
#else
@ -149,8 +159,8 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
#endif
}
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer.
/// EnterSourceFileWithLexer - Add a source file to the top of the include stack
/// and start lexing tokens from it instead of the current buffer.
void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
const DirectoryLookup *CurDir) {
@ -172,7 +182,27 @@ void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
}
}
/// EnterSourceFileWithPTH - Add a source file to the top of the include stack
/// and start getting tokens from it using the PTH cache.
void Preprocessor::EnterSourceFileWithPTH(PTHLexer *PL,
const DirectoryLookup *CurDir) {
if (CurPPLexer || CurTokenLexer)
PushIncludeMacroStack();
CurDirLookup = CurDir;
CurPTHLexer.reset(PL);
CurPPLexer = CurPTHLexer.get();
// Notify the client, if desired, that we are in a new source file.
if (Callbacks) {
unsigned FileID = CurPPLexer->getFileID();
SrcMgr::CharacteristicKind FileType =
SourceMgr.getFileCharacteristic(CurPPLexer->getFileID());
Callbacks->FileChanged(SourceLocation::getFileLoc(FileID, 0),
PPCallbacks::EnterFile, FileType);
}
}
/// EnterMacro - Add a Macro to the top of the include stack and start lexing
/// tokens from it instead of the current buffer.