]> granicus.if.org Git - clang/commitdiff
Add PTHLexer::LexEndOfFile() to emit diagnostics at end-of-file similar to those...
authorTed Kremenek <kremenek@apple.com>
Tue, 27 Jul 2010 02:59:02 +0000 (02:59 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 27 Jul 2010 02:59:02 +0000 (02:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109486 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/PTHLexer.h
lib/Lex/PTHLexer.cpp

index e96a8c514e6eb14a8cf39cca1bea9b5ba69b2482..0b5a76ccfd6e0cc603faca36cccc77917ac3a015 100644 (file)
@@ -50,6 +50,8 @@ class PTHLexer : public PreprocessorLexer {
 
   /// 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;
index 3b949d0ab40a15c3db36f856a4d9f241f3a02d01..60b6e045265ebafd01f80096ac08582324f3f4e1 100644 (file)
@@ -101,16 +101,15 @@ LexNextToken:
     // 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 @@ LexNextToken:
   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) {