aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PTHLexer.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-11-21 00:58:35 +0000
committerTed Kremenek <kremenek@apple.com>2008-11-21 00:58:35 +0000
commitcd4e2aecde5bb7810715d5d5a88ac63ce7946f34 (patch)
treee7146c6fc739408f5939fb05a858367f8b3dad64 /lib/Lex/PTHLexer.cpp
parentbd71be4683c195260d5245118b1e13e6b2e20504 (diff)
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
Diffstat (limited to 'lib/Lex/PTHLexer.cpp')
-rw-r--r--lib/Lex/PTHLexer.cpp40
1 files changed, 26 insertions, 14 deletions
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];
}