diff options
author | Chris Lattner <sabre@nondot.org> | 2008-10-12 01:15:46 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-10-12 01:15:46 +0000 |
commit | 50c9050037a1388072f8efaed98e1dc8050bedb4 (patch) | |
tree | 3a2a64f5271516e92fa7b8c16d13f5a01336dfd9 /clang/lib/Lex | |
parent | 5d3e26a4f68c38fd98014a5344e6bb4095c38eac (diff) | |
download | bcm5719-llvm-50c9050037a1388072f8efaed98e1dc8050bedb4.tar.gz bcm5719-llvm-50c9050037a1388072f8efaed98e1dc8050bedb4.zip |
Change how raw lexers are handled: instead of creating them and then
using LexRawToken, create one and use LexFromRawLexer. This avoids
twiddling the RawLexer flag around and simplifies some code (even
speeding raw lexing up a tiny bit).
This change also improves the token paster to use a Lexer on the stack
instead of new/deleting it.
llvm-svn: 57393
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Lex/TokenLexer.cpp | 12 |
2 files changed, 12 insertions, 11 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index c99dc1d4b84..e930f3def2e 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -104,15 +104,16 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &pp, } /// Lexer constructor - Create a new raw lexer object. This object is only -/// suitable for calls to 'LexRawToken'. This lexer assumes that the -/// associated file buffer will outlive it, so it doesn't take ownership of it. +/// suitable for calls to 'LexRawToken'. This lexer assumes that the text +/// range will outlive it, so it doesn't take ownership of it. Lexer::Lexer(SourceLocation fileloc, const LangOptions &features, - const char *BufStart, const char *BufEnd) + const char *BufStart, const char *BufEnd, + const llvm::MemoryBuffer *FromFile) : FileLoc(fileloc), PP(0), Features(features) { Is_PragmaLexer = false; InitCharacterInfo(); - BufferStart = BufStart; + BufferStart = FromFile ? FromFile->getBufferStart() : BufStart; BufferPtr = BufStart; BufferEnd = BufEnd; @@ -192,7 +193,7 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc, // Create a lexer starting at the beginning of this token. Lexer TheLexer(Loc, LangOpts, StrData, BufEnd); Token TheTok; - TheLexer.LexRawToken(TheTok); + TheLexer.LexFromRawLexer(TheTok); return TheTok.getLength(); } diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp index a3fe7350f2a..d3acaeaab54 100644 --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -396,23 +396,23 @@ bool TokenLexer::PasteTokens(Token &Tok) { SourceManager &SourceMgr = PP.getSourceManager(); const char *ResultStrData = SourceMgr.getCharacterData(ResultTokLoc); + const llvm::MemoryBuffer *Buffer = + SourceMgr.getBuffer(ResultTokLoc.getFileID()); + // Make a lexer object so that we lex and expand the paste result. - Lexer *TL = new Lexer(ResultTokLoc, PP, ResultStrData, - ResultStrData+LHSLen+RHSLen /*don't include null*/); + Lexer TL(ResultTokLoc, PP.getLangOptions(), ResultStrData, + ResultStrData+LHSLen+RHSLen /*don't include null*/, Buffer); // Lex a token in raw mode. This way it won't look up identifiers // automatically, lexing off the end will return an eof token, and // warnings are disabled. This returns true if the result token is the // entire buffer. - bool IsComplete = TL->LexRawToken(Result); + bool IsComplete = TL.LexFromRawLexer(Result); // If we got an EOF token, we didn't form even ONE token. For example, we // did "/ ## /" to get "//". IsComplete &= Result.isNot(tok::eof); isInvalid = !IsComplete; - - // We're now done with the temporary lexer. - delete TL; } // If pasting the two tokens didn't form a full new token, this is an error. |