diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-11-20 07:56:33 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-11-20 07:56:33 +0000 |
commit | 85b48c6e3aa1beef91ae1d794beee26f310baf56 (patch) | |
tree | 7e451f320d4f3fe853386a23d03c27f445bbbf02 /clang/lib/Lex/PPLexerChange.cpp | |
parent | f4fd9b7ec49cbaf6f3911fe9b337893748994364 (diff) | |
download | bcm5719-llvm-85b48c6e3aa1beef91ae1d794beee26f310baf56.tar.gz bcm5719-llvm-85b48c6e3aa1beef91ae1d794beee26f310baf56.zip |
Add ugly "test harness" for PTHLexer that is not enabled by default. The
(temporary hack) to test the PTHLexer is that whenever we would create a Lexer
object we instead raw lex a memory buffer first and then use the PTHLexer. This
logic exists only to driver the PTHLexer and will be removed/changed in the
future. Note that the regular path using normal Lexer objects is what is used by
default.
llvm-svn: 59723
Diffstat (limited to 'clang/lib/Lex/PPLexerChange.cpp')
-rw-r--r-- | clang/lib/Lex/PPLexerChange.cpp | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index 1df4d210b84..973eced1cdb 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -17,6 +17,8 @@ #include "clang/Lex/MacroInfo.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" +#include "llvm/Support/MemoryBuffer.h" + using namespace clang; PPCallbacks::~PPCallbacks() {} @@ -72,8 +74,50 @@ void Preprocessor::EnterSourceFile(unsigned FileID, if (MaxIncludeStackDepth < IncludeMacroStack.size()) MaxIncludeStackDepth = IncludeMacroStack.size(); +#if 1 Lexer *TheLexer = new Lexer(SourceLocation::getFileLoc(FileID, 0), *this); EnterSourceFileWithLexer(TheLexer, CurDir); +#else + const llvm::MemoryBuffer* B = getSourceManager().getBuffer(FileID); + + // Create a raw lexer. + Lexer L(SourceLocation::getFileLoc(FileID, 0), getLangOptions(), + B->getBufferStart(), B->getBufferEnd(), B); + + // Ignore whitespace. + L.SetKeepWhitespaceMode(false); + L.SetCommentRetentionState(false); + + // Lex the file, populating our data structures. + std::vector<Token>* Tokens = new std::vector<Token>(); + Token Tok; + + do { + L.LexFromRawLexer(Tok); + + if (Tok.is(tok::identifier)) + Tok.setIdentifierInfo(LookUpIdentifierInfo(Tok)); + + // Store the token. + Tokens->push_back(Tok); + } + while (Tok.isNot(tok::eof)); + + if (CurPPLexer || CurTokenLexer) + PushIncludeMacroStack(); + + CurDirLookup = CurDir; + SourceLocation Loc = SourceLocation::getFileLoc(FileID, 0); + CurPTHLexer.reset(new PTHLexer(*this, Loc, &(*Tokens)[0], Tokens->size())); + CurPPLexer = CurPTHLexer.get(); + + // Notify the client, if desired, that we are in a new source file. + if (Callbacks) { + SrcMgr::CharacteristicKind FileType = + SourceMgr.getFileCharacteristic(CurPPLexer->getFileID()); + Callbacks->FileChanged(Loc, PPCallbacks::EnterFile, FileType); + } +#endif } /// EnterSourceFile - Add a source file to the top of the include stack and @@ -172,14 +216,15 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) { if (Callbacks && !isEndOfMacro && CurPPLexer) { SrcMgr::CharacteristicKind FileType = SourceMgr.getFileCharacteristic(CurPPLexer->getFileID()); - + if (CurLexer) { - // FIXME: Should we use the location of 'Result'? Callbacks->FileChanged(CurLexer->getSourceLocation(CurLexer->BufferPtr), PPCallbacks::ExitFile, FileType); } else { - assert (0 && "FIXME: Add callback support for PTHLexer."); + // FIXME: Is this okay to use the location of 'Result'? + Callbacks->FileChanged(Result.getLocation(), PPCallbacks::ExitFile, + FileType); } } @@ -258,9 +303,7 @@ void Preprocessor::RemoveTopOfLexerStack() { CurTokenLexer.reset(); else TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.take(); - } else { - CurLexer.reset(); - } + } PopIncludeMacroStack(); } |