Preprocessor:

- 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.

llvm-svn: 60437
This commit is contained in:
Ted Kremenek 2008-12-02 19:46:31 +00:00
parent 498b6210fc
commit af058b5696
2 changed files with 44 additions and 4 deletions

View File

@ -18,6 +18,7 @@
#include "clang/Lex/PTHLexer.h" #include "clang/Lex/PTHLexer.h"
#include "clang/Lex/PPCallbacks.h" #include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/TokenLexer.h" #include "clang/Lex/TokenLexer.h"
#include "clang/Lex/PTHManager.h"
#include "clang/Basic/Diagnostic.h" #include "clang/Basic/Diagnostic.h"
#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceLocation.h"
@ -36,7 +37,7 @@ class ScratchBuffer;
class TargetInfo; class TargetInfo;
class PPCallbacks; class PPCallbacks;
class DirectoryLookup; class DirectoryLookup;
/// Preprocessor - This object engages in a tight little dance with the lexer to /// Preprocessor - This object engages in a tight little dance with the lexer to
/// efficiently preprocess tokens. Lexers know only about tokens within a /// efficiently preprocess tokens. Lexers know only about tokens within a
/// single source file, and don't know anything about preprocessor-level issues /// single source file, and don't know anything about preprocessor-level issues
@ -50,6 +51,10 @@ class Preprocessor {
SourceManager &SourceMgr; SourceManager &SourceMgr;
ScratchBuffer *ScratchBuf; ScratchBuffer *ScratchBuf;
HeaderSearch &HeaderInfo; 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. /// Identifiers for builtin macros and other builtins.
IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__ IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
@ -189,6 +194,8 @@ public:
IdentifierTable &getIdentifierTable() { return Identifiers; } IdentifierTable &getIdentifierTable() { return Identifiers; }
SelectorTable &getSelectorTable() { return Selectors; } SelectorTable &getSelectorTable() { return Selectors; }
void setPTHManager(PTHManager* pm) { PTH.reset(pm); }
/// SetCommentRetentionState - Control whether or not the preprocessor retains /// SetCommentRetentionState - Control whether or not the preprocessor retains
/// comments in output. /// comments in output.
@ -591,10 +598,13 @@ private:
/// been read into 'Tok'. /// been read into 'Tok'.
void Handle_Pragma(Token &Tok); void Handle_Pragma(Token &Tok);
/// EnterSourceFileWithLexer - Add a lexer to the top of the include stack and /// EnterSourceFileWithLexer - Add a lexer to the top of the include stack and
/// start lexing tokens from it instead of the current buffer. /// start lexing tokens from it instead of the current buffer.
void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir); 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 /// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully
/// checked and spelled filename, e.g. as an operand of #include. This returns /// checked and spelled filename, e.g. as an operand of #include. This returns

View File

@ -75,6 +75,16 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
MaxIncludeStackDepth = IncludeMacroStack.size(); MaxIncludeStackDepth = IncludeMacroStack.size();
#if 1 #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); Lexer *TheLexer = new Lexer(SourceLocation::getFileLoc(FileID, 0), *this);
EnterSourceFileWithLexer(TheLexer, CurDir); EnterSourceFileWithLexer(TheLexer, CurDir);
#else #else
@ -149,8 +159,8 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
#endif #endif
} }
/// EnterSourceFile - Add a source file to the top of the include stack and /// EnterSourceFileWithLexer - Add a source file to the top of the include stack
/// start lexing tokens from it instead of the current buffer. /// and start lexing tokens from it instead of the current buffer.
void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer, void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
const DirectoryLookup *CurDir) { 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 /// EnterMacro - Add a Macro to the top of the include stack and start lexing
/// tokens from it instead of the current buffer. /// tokens from it instead of the current buffer.