[cfe-commits] r60905 - in /cfe/trunk: include/clang/Lex/PTHLexer.h lib/Lex/PTHLexer.cpp
Ted Kremenek
kremenek at apple.com
Thu Dec 11 14:42:13 PST 2008
Author: kremenek
Date: Thu Dec 11 16:41:47 2008
New Revision: 60905
URL: http://llvm.org/viewvc/llvm-project?rev=60905&view=rev
Log:
PTHLexer: Keep track of the location of the last '#' token and provide the means to jump ahead in the token stream.
Modified:
cfe/trunk/include/clang/Lex/PTHLexer.h
cfe/trunk/lib/Lex/PTHLexer.cpp
Modified: cfe/trunk/include/clang/Lex/PTHLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHLexer.h?rev=60905&r1=60904&r2=60905&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Thu Dec 11 16:41:47 2008
@@ -24,6 +24,14 @@
class PTHLexer : public PreprocessorLexer {
/// TokBuf - Buffer from PTH file containing raw token data.
const char* TokBuf;
+
+ /// CurPtr - Pointer into current offset of the token buffer where
+ /// the next token will be read.
+ const char* CurPtr;
+
+ /// LastHashTokPtr - Pointer into TokBuf of the last processed '#'
+ /// token that appears at the start of a line.
+ const char* LastHashTokPtr;
PTHLexer(const PTHLexer&); // DO NOT IMPLEMENT
void operator=(const PTHLexer&); // DO NOT IMPLEMENT
@@ -72,6 +80,14 @@
private:
+ /// SkipToToken - Skip to the token at the specified offset in TokBuf.
+ void SkipToToken(unsigned offset) {
+ const char* NewPtr = TokBuf + offset;
+ assert(NewPtr > CurPtr && "SkipToToken should not go backwards!");
+ NeedsFetching = true;
+ CurPtr = NewPtr;
+ }
+
/// AtLastToken - Returns true if the PTHLexer is at the last token.
bool AtLastToken() {
Token T = GetToken();
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=60905&r1=60904&r2=60905&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Thu Dec 11 16:41:47 2008
@@ -28,7 +28,8 @@
PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D,
PTHManager& PM)
- : PreprocessorLexer(&pp, fileloc), TokBuf(D), PTHMgr(PM),
+ : PreprocessorLexer(&pp, fileloc), TokBuf(D), CurPtr(D), LastHashTokPtr(0),
+ PTHMgr(PM),
NeedsFetching(true) {
// Make sure the EofToken is completely clean.
EofToken.startToken();
@@ -82,6 +83,8 @@
if (Tok.is(tok::hash)) {
if (Tok.isAtStartOfLine() && !LexingRawMode) {
+ LastHashTokPtr = CurPtr;
+
PP->HandleDirective(Tok);
if (PP->isCurrentLexer(this))
@@ -163,20 +166,20 @@
T.startToken();
// Read the type of the token.
- T.setKind((tok::TokenKind) Read8(TokBuf));
+ T.setKind((tok::TokenKind) Read8(CurPtr));
// Set flags. This is gross, since we are really setting multiple flags.
- T.setFlag((Token::TokenFlags) Read8(TokBuf));
+ T.setFlag((Token::TokenFlags) Read8(CurPtr));
// Set the IdentifierInfo* (if any).
- T.setIdentifierInfo(PTHMgr.ReadIdentifierInfo(TokBuf));
+ T.setIdentifierInfo(PTHMgr.ReadIdentifierInfo(CurPtr));
// Set the SourceLocation. Since all tokens are constructed using a
// raw lexer, they will all be offseted from the same FileID.
- T.setLocation(SourceLocation::getFileLoc(FileID, Read32(TokBuf)));
+ T.setLocation(SourceLocation::getFileLoc(FileID, Read32(CurPtr)));
// Finally, read and set the length of the token.
- T.setLength(Read32(TokBuf));
+ T.setLength(Read32(CurPtr));
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list