diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-07-11 05:46:12 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-07-11 05:46:12 +0000 |
| commit | 678c880a69c398024e08cb2cbb55c04dfadbd07a (patch) | |
| tree | d07373831d53e3397d464437321a9fcff51506fb /clang/Lex/Lexer.cpp | |
| parent | 3ebcf4e2cd606f3d649e94bdeced50e924b878a4 (diff) | |
| download | bcm5719-llvm-678c880a69c398024e08cb2cbb55c04dfadbd07a.tar.gz bcm5719-llvm-678c880a69c398024e08cb2cbb55c04dfadbd07a.zip | |
Move Preprocessor::isNextPPTokenLParen to Lexer::isNextPPTokenLParen, where
it more rightly belongs.
llvm-svn: 38702
Diffstat (limited to 'clang/Lex/Lexer.cpp')
| -rw-r--r-- | clang/Lex/Lexer.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp index 2a1bcc0248f..7b4cbd7962d 100644 --- a/clang/Lex/Lexer.cpp +++ b/clang/Lex/Lexer.cpp @@ -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 |

