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
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index a88470b..5c6341f 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -41,24 +41,18 @@
void PTHLexer::Lex(Token& Tok) {
LexNextToken:
- if (AtLastToken()) {
- if (ParsingPreprocessorDirective) {
- ParsingPreprocessorDirective = false;
- Tok = GetToken();
- Tok.setKind(tok::eom);
- MIOpt.ReadToken();
- return;
- }
-
- assert(!LexingRawMode && "PTHLexer cannot lex in raw mode.");
-
- // FIXME: Issue diagnostics similar to Lexer.
- PP->HandleEndOfFile(Tok, false);
- return;
- }
-
Tok = GetToken();
+ if (AtLastToken()) {
+ Preprocessor *PPCache = PP;
+
+ if (LexEndOfFile(Tok))
+ return;
+
+ 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
// consume this token twice, once as an tok::eom.
@@ -91,6 +85,24 @@
}
}
+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];
}