aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Lexer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-01-17 07:56:59 +0000
committerChris Lattner <sabre@nondot.org>2009-01-17 07:56:59 +0000
commit0770dabb1ae81a2a9c2e7199262067103062a0b3 (patch)
tree2f00512a213936fc67957cdeac9d66265dd8952e /lib/Lex/Lexer.cpp
parentde96c0f29c4cacabe6ea577c61db87c2a85aea6c (diff)
More simplifications to the lexer ctors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62419 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r--lib/Lex/Lexer.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index c5b36fce61..c379f58b0c 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -90,6 +90,28 @@ void Lexer::InitLexer(const char *BufStart, const char *BufPtr,
ExtendedTokenMode = 0;
}
+/// Lexer constructor - Create a new lexer object for the specified buffer
+/// with the specified preprocessor managing the lexing process. This lexer
+/// assumes that the associated file buffer and Preprocessor objects will
+/// outlive it, so it doesn't take ownership of either of them.
+Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP)
+// FIXME: This is really horrible and only needed for _Pragma lexers, split this
+// out of the main lexer path!
+: PreprocessorLexer(&PP,
+ PP.getSourceManager().getCanonicalFileID(
+ PP.getSourceManager().getSpellingLoc(fileloc))),
+ FileLoc(fileloc),
+ Features(PP.getLangOptions()) {
+
+ SourceManager &SourceMgr = PP.getSourceManager();
+ const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(getFileID());
+
+ InitLexer(InputFile->getBufferStart(), InputFile->getBufferStart(),
+ InputFile->getBufferEnd());
+
+ // Default to keeping comments if the preprocessor wants them.
+ SetCommentRetentionState(PP.getCommentRetentionState());
+}
/// Lexer constructor - Create a new lexer object for the specified buffer
/// with the specified preprocessor managing the lexing process. This lexer
@@ -105,16 +127,8 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP,
FileLoc(fileloc),
Features(PP.getLangOptions()) {
- SourceManager &SourceMgr = PP.getSourceManager();
- const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(getFileID());
-
- // BufferPtr and BufferEnd can start out somewhere inside the current buffer.
- // If unspecified, they starts at the start/end of the buffer.
- const char *BufStart = InputFile->getBufferStart();
- if (BufPtr == 0) BufPtr = BufStart;
- if (BufEnd == 0) BufEnd = InputFile->getBufferEnd();
-
- InitLexer(BufStart, BufPtr, BufEnd);
+ InitLexer(PP.getSourceManager().getBuffer(getFileID())->getBufferStart(),
+ BufPtr, BufEnd);
// Default to keeping comments if the preprocessor wants them.
SetCommentRetentionState(PP.getCommentRetentionState());