[cfe-commits] r109486 - in /cfe/trunk: include/clang/Lex/PTHLexer.h lib/Lex/PTHLexer.cpp
Ted Kremenek
kremenek at apple.com
Mon Jul 26 19:59:02 PDT 2010
Author: kremenek
Date: Mon Jul 26 21:59:02 2010
New Revision: 109486
URL: http://llvm.org/viewvc/llvm-project?rev=109486&view=rev
Log:
Add PTHLexer::LexEndOfFile() to emit diagnostics at end-of-file similar to those by Lexer::LexEndOfFile().
Modified:
cfe/trunk/include/clang/Lex/PTHLexer.h
cfe/trunk/lib/Lex/PTHLexer.cpp
Modified: cfe/trunk/include/clang/Lex/PTHLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHLexer.h?rev=109486&r1=109485&r2=109486&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Mon Jul 26 21:59:02 2010
@@ -50,6 +50,8 @@
/// ReadToken - Used by PTHLexer to read tokens TokBuf.
void ReadToken(Token& T);
+
+ bool LexEndOfFile(Token &Result);
/// PTHMgr - The PTHManager object that created this PTHLexer.
PTHManager& PTHMgr;
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=109486&r1=109485&r2=109486&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Mon Jul 26 21:59:02 2010
@@ -101,16 +101,15 @@
// Save the end-of-file token.
EofToken = Tok;
+ // Save 'PP' to 'PPCache' as LexEndOfFile can delete 'this'.
Preprocessor *PPCache = PP;
assert(!ParsingPreprocessorDirective);
assert(!LexingRawMode);
-
- // FIXME: Issue diagnostics similar to Lexer.
- if (PP->HandleEndOfFile(Tok, false))
+
+ if (LexEndOfFile(Tok))
return;
- assert(PPCache && "Raw buffer::LexEndOfFile should return a token");
return PPCache->Lex(Tok);
}
@@ -134,6 +133,28 @@
MIOpt.ReadToken();
}
+bool PTHLexer::LexEndOfFile(Token &Result) {
+ // If we hit the end of the file while parsing a preprocessor directive,
+ // end the preprocessor directive first. The next token returned will
+ // then be the end of file.
+ if (ParsingPreprocessorDirective) {
+ ParsingPreprocessorDirective = false; // Done parsing the "line".
+ return true; // Have a token.
+ }
+
+ assert(!LexingRawMode);
+
+ // If we are in a #if directive, emit an error.
+ while (!ConditionalStack.empty()) {
+ PP->Diag(ConditionalStack.back().IfLoc,
+ diag::err_pp_unterminated_conditional);
+ ConditionalStack.pop_back();
+ }
+
+ // Finally, let the preprocessor handle this.
+ return PP->HandleEndOfFile(Result);
+}
+
// FIXME: We can just grab the last token instead of storing a copy
// into EofToken.
void PTHLexer::getEOF(Token& Tok) {
More information about the cfe-commits
mailing list