diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Lex/Lexer.cpp | 15 | ||||
-rw-r--r-- | lib/Rewrite/HTMLRewrite.cpp | 7 | ||||
-rw-r--r-- | lib/Rewrite/TokenRewriter.cpp | 5 |
3 files changed, 17 insertions, 10 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index e89815029d..704c4db661 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -127,7 +127,6 @@ Lexer::Lexer(SourceLocation fileloc, const LangOptions &features, const char *BufPtr, const char *BufEnd, const llvm::MemoryBuffer *FromFile) : FileLoc(fileloc), Features(features) { - // If a MemoryBuffer was specified, use its start as BufferStart. This affects // the source location objects produced by this lexer. @@ -140,6 +139,20 @@ Lexer::Lexer(SourceLocation fileloc, const LangOptions &features, LexingRawMode = true; } +/// Lexer constructor - Create a new raw lexer object. This object is only +/// 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(FileID FID, const SourceManager &SM, const LangOptions &features) + : FileLoc(SM.getLocForStartOfFile(FID)), Features(features) { + const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID); + + InitLexer(FromFile->getBufferStart(), FromFile->getBufferStart(), + FromFile->getBufferEnd()); + + // We *are* in raw mode. + LexingRawMode = true; +} + /// Stringify - Convert the specified string into a C string, with surrounding /// ""'s, and with escaped \ and " characters. diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index d61da4010a..68a53d364b 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -344,11 +344,8 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) { RewriteBuffer &RB = R.getEditBuffer(FID); const SourceManager &SourceMgr = PP.getSourceManager(); - std::pair<const char*, const char*> File = SourceMgr.getBufferData(FID); - const char *BufferStart = File.first; - - Lexer L(SourceMgr.getLocForStartOfFile(FID), - PP.getLangOptions(), File.first, File.second); + Lexer L(FID, SourceMgr, PP.getLangOptions()); + const char *BufferStart = L.getBufferStart(); // Inform the preprocessor that we want to retain comments as tokens, so we // can highlight them. diff --git a/lib/Rewrite/TokenRewriter.cpp b/lib/Rewrite/TokenRewriter.cpp index 85d83c2dea..aab6fb0cce 100644 --- a/lib/Rewrite/TokenRewriter.cpp +++ b/lib/Rewrite/TokenRewriter.cpp @@ -22,11 +22,8 @@ TokenRewriter::TokenRewriter(FileID FID, SourceManager &SM, const LangOptions &LangOpts) { ScratchBuf.reset(new ScratchBuffer(SM)); - std::pair<const char*,const char*> File = SM.getBufferData(FID); - // Create a lexer to lex all the tokens of the main file in raw mode. - Lexer RawLex(SM.getLocForStartOfFile(FID), - LangOpts, File.first, File.second); + Lexer RawLex(FID, SM, LangOpts); // Return all comments and whitespace as tokens. RawLex.SetKeepWhitespaceMode(true); |