From cd4e2aecde5bb7810715d5d5a88ac63ce7946f34 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 21 Nov 2008 00:58:35 +0000 Subject: [PATCH] PTHLexer: - Move out logic for handling the end-of-file to LexEndOfFile (to match the Lexer) class. The logic now mirrors the Lexer class more, which allows us to pass most of the Preprocessor test cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59768 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/PTHLexer.h | 2 ++ lib/Lex/PTHLexer.cpp | 40 +++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/clang/Lex/PTHLexer.h b/include/clang/Lex/PTHLexer.h index 6f53c61750..3218a1dd5d 100644 --- a/include/clang/Lex/PTHLexer.h +++ b/include/clang/Lex/PTHLexer.h @@ -72,6 +72,8 @@ private: /// AdvanceToken - Advances the PTHLexer to the next token. void AdvanceToken() { ++CurTokenIdx; } + + bool LexEndOfFile(Token &Result); }; } // end namespace clang diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index a88470bbad..5c6341f57d 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -41,23 +41,17 @@ Token PTHLexer::GetToken() { void PTHLexer::Lex(Token& Tok) { LexNextToken: + Tok = GetToken(); + if (AtLastToken()) { - if (ParsingPreprocessorDirective) { - ParsingPreprocessorDirective = false; - Tok = GetToken(); - Tok.setKind(tok::eom); - MIOpt.ReadToken(); + Preprocessor *PPCache = PP; + + if (LexEndOfFile(Tok)) return; - } - - assert(!LexingRawMode && "PTHLexer cannot lex in raw mode."); - - // FIXME: Issue diagnostics similar to Lexer. - PP->HandleEndOfFile(Tok, false); - return; - } - Tok = GetToken(); + assert(PPCache && "Raw buffer::LexEndOfFile should return a token"); + return PPCache->Lex(Tok); + } // Don't advance to the next token yet. Check if we are at the // start of a new line and we're processing a directive. If so, we @@ -91,6 +85,24 @@ LexNextToken: } } +bool PTHLexer::LexEndOfFile(Token &Tok) { + + if (ParsingPreprocessorDirective) { + ParsingPreprocessorDirective = false; + Tok.setKind(tok::eom); + MIOpt.ReadToken(); + return true; // Have a token. + } + + if (LexingRawMode) { + MIOpt.ReadToken(); + return true; // Have an eof token. + } + + // FIXME: Issue diagnostics similar to Lexer. + return PP->HandleEndOfFile(Tok, false); +} + void PTHLexer::setEOF(Token& Tok) { Tok = Tokens[LastTokenIdx]; } -- 2.40.0