Move Preprocessor::isNextPPTokenLParen to Lexer::isNextPPTokenLParen, where

it more rightly belongs.

llvm-svn: 38702
This commit is contained in:
Chris Lattner 2006-07-11 05:46:12 +00:00
parent 3ebcf4e2cd
commit 678c880a69
4 changed files with 44 additions and 45 deletions

View File

@ -39,8 +39,7 @@ static void InitCharacterInfo();
Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp,
const char *BufStart, const char *BufEnd)
: BufferPtr(BufStart ? BufStart : File->getBufferStart()),
BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
: BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
InputFile(File), CurFileID(fileid), PP(pp), Features(PP.getLangOptions()) {
Is_PragmaLexer = false;
IsMainFile = false;
@ -49,7 +48,9 @@ Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp,
assert(BufferEnd[0] == 0 &&
"We assume that the input buffer has a null character at the end"
" to simplify lexing!");
BufferPtr = BufStart ? BufStart : File->getBufferStart();
// Start of the file is a start of line.
IsAtStartOfLine = true;
@ -922,6 +923,36 @@ void Lexer::LexEndOfFile(LexerToken &Result, const char *CurPtr) {
PP.HandleEndOfFile(Result);
}
/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
/// the specified lexer will return a tok::l_paren token, 0 if it is something
/// else and 2 if there are no more tokens in the buffer controlled by the
/// lexer.
unsigned Lexer::isNextPPTokenLParen() {
assert(!LexingRawMode && "How can we expand a macro from a skipping buffer?");
// Switch to 'skipping' mode. This will ensure that we can lex a token
// without emitting diagnostics, disables macro expansion, and will cause EOF
// to return an EOF token instead of popping the include stack.
LexingRawMode = true;
// Save state that can be changed while lexing so that we can restore it.
const char *TmpBufferPtr = BufferPtr;
LexerToken Tok;
Tok.StartToken();
LexTokenInternal(Tok);
// Restore state that may have changed.
BufferPtr = TmpBufferPtr;
// Restore the lexer back to non-skipping mode.
LexingRawMode = false;
if (Tok.getKind() == tok::eof)
return 2;
return Tok.getKind() == tok::l_paren;
}
/// LexTokenInternal - This implements a simple C family lexer. It is an
/// extremely performance critical piece of code. This assumes that the buffer

View File

@ -506,37 +506,6 @@ static bool isTrivialSingleTokenExpansion(const MacroInfo *MI,
return true;
}
/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
/// the specified lexer will return a tok::l_paren token, 0 if it is something
/// else and 2 if there are no more tokens in the buffer controlled by the
/// lexer.
unsigned Preprocessor::isNextPPTokenLParen(Lexer *L) {
assert(!L->LexingRawMode &&
"How can we expand a macro from a skipping buffer?");
// Set the lexer to 'skipping' mode. This will ensure that we can lex a token
// without emitting diagnostics, disables macro expansion, and will cause EOF
// to return an EOF token instead of popping the include stack.
L->LexingRawMode = true;
// Save state that can be changed while lexing so that we can restore it.
const char *BufferPtr = L->BufferPtr;
LexerToken Tok;
Tok.StartToken();
L->LexTokenInternal(Tok);
// Restore state that may have changed.
L->BufferPtr = BufferPtr;
// Restore the lexer back to non-skipping mode.
L->LexingRawMode = false;
if (Tok.getKind() == tok::eof)
return 2;
return Tok.getKind() == tok::l_paren;
}
/// isNextPPTokenLParen - Determine whether the next preprocessor token to be
/// lexed is a '('. If so, consume the token and return true, if not, this
@ -545,7 +514,7 @@ bool Preprocessor::isNextPPTokenLParen() {
// Do some quick tests for rejection cases.
unsigned Val;
if (CurLexer)
Val = isNextPPTokenLParen(CurLexer);
Val = CurLexer->isNextPPTokenLParen();
else
Val = CurMacroExpander->isNextTokenLParen();
@ -555,7 +524,7 @@ bool Preprocessor::isNextPPTokenLParen() {
for (unsigned i = IncludeMacroStack.size(); Val == 2 && i != 0; --i) {
IncludeStackInfo &Entry = IncludeMacroStack[i-1];
if (Entry.TheLexer)
Val = isNextPPTokenLParen(Entry.TheLexer);
Val = Entry.TheLexer->isNextPPTokenLParen();
else
Val = Entry.TheMacroExpander->isNextTokenLParen();
}

View File

@ -86,8 +86,9 @@ class Lexer {
bool LexingRawMode;
//===--------------------------------------------------------------------===//
// Context that changes as the file is lexed. NOTE: any state that mutates as
// the file is lexed should be added to Preprocessor::isNextPPTokenLParen.
// Context that changes as the file is lexed.
// NOTE: any state that mutates when in raw mode must have save/restore code
// in Lexer::isNextPPTokenLParen.
// BufferPtr - Current pointer into the buffer. This is the next character
// to be lexed.
@ -191,7 +192,11 @@ private:
BufferPtr = TokEnd;
}
/// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
/// tok::l_paren token, 0 if it is something else and 2 if there are no more
/// tokens in the buffer controlled by this lexer.
unsigned isNextPPTokenLParen();
//===--------------------------------------------------------------------===//
// Lexer character reading interfaces.

View File

@ -466,12 +466,6 @@ private:
/// the macro should not be expanded return true, otherwise return false.
bool HandleMacroExpandedIdentifier(LexerToken &Tok, MacroInfo *MI);
/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
/// the specified lexer will return a tok::l_paren token, 0 if it is something
/// else and 2 if there are no more tokens in the buffer controlled by the
/// lexer.
unsigned isNextPPTokenLParen(Lexer *L);
/// isNextPPTokenLParen - Determine whether the next preprocessor token to be
/// lexed is a '('. If so, consume the token and return true, if not, this
/// method should have no observable side-effect on the lexed tokens.