refactor some common initialization code out of the two lexer ctors.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62411 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-01-17 06:55:17 +00:00
Родитель 6c9f8aaa67
Коммит 22d91ca8d7
2 изменённых файлов: 47 добавлений и 52 удалений

Просмотреть файл

@ -69,6 +69,8 @@ class Lexer : public PreprocessorLexer {
Lexer(const Lexer&); // DO NOT IMPLEMENT
void operator=(const Lexer&); // DO NOT IMPLEMENT
friend class Preprocessor;
void InitLexer(const char *BufStart, const char *BufPtr, const char *BufEnd);
public:
/// Lexer constructor - Create a new lexer object for the specified buffer

Просмотреть файл

@ -57,39 +57,20 @@ tok::ObjCKeywordKind Token::getObjCKeywordID() const {
// Lexer Class Implementation
//===----------------------------------------------------------------------===//
/// 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,
const char *BufStart, const char *BufEnd)
// 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());
Is_PragmaLexer = false;
void Lexer::InitLexer(const char *BufStart, const char *BufPtr,
const char *BufEnd) {
InitCharacterInfo();
// BufferStart must always be InputFile->getBufferStart().
BufferStart = InputFile->getBufferStart();
BufferStart = BufStart;
BufferPtr = BufPtr;
BufferEnd = BufEnd;
// BufferPtr and BufferEnd can start out somewhere inside the current buffer.
// If unspecified, they starts at the start/end of the buffer.
BufferPtr = BufStart ? BufStart : BufferStart;
BufferEnd = BufEnd ? BufEnd : InputFile->getBufferEnd();
assert(BufferEnd[0] == 0 &&
assert(BufEnd[0] == 0 &&
"We assume that the input buffer has a null character at the end"
" to simplify lexing!");
Is_PragmaLexer = false;
// Start of the file is a start of line.
IsAtStartOfLine = true;
@ -105,8 +86,37 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP,
// or otherwise skipping over tokens.
LexingRawMode = false;
// Default to keeping comments if the preprocessor wants them.
// Default to not keeping comments.
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,
const char *BufPtr, const char *BufEnd)
// 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());
// 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);
// Default to keeping comments if the preprocessor wants them.
SetCommentRetentionState(PP.getCommentRetentionState());
}
@ -114,37 +124,20 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP,
/// 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 *BufPtr, const char *BufEnd,
const llvm::MemoryBuffer *FromFile)
: FileLoc(fileloc), Features(features) {
Is_PragmaLexer = false;
InitCharacterInfo();
// If a MemoryBuffer was specified, use its start as BufferStart. This affects
// the source location objects produced by this lexer.
BufferStart = FromFile ? FromFile->getBufferStart() : BufStart;
BufferPtr = BufStart;
BufferEnd = BufEnd;
const char *BufStart = BufPtr;
if (FromFile) BufStart = FromFile->getBufferStart();
assert(BufferEnd[0] == 0 &&
"We assume that the input buffer has a null character at the end"
" to simplify lexing!");
// Start of the file is a start of line.
IsAtStartOfLine = true;
// We are not after parsing a #.
ParsingPreprocessorDirective = false;
// We are not after parsing #include.
ParsingFilename = false;
InitLexer(BufStart, BufPtr, BufEnd);
// We *are* in raw mode.
LexingRawMode = true;
// Default to not keeping comments in raw mode.
ExtendedTokenMode = 0;
}