[cfe-commits] r59768 - in /cfe/trunk: include/clang/Lex/PTHLexer.h lib/Lex/PTHLexer.cpp

Ted Kremenek kremenek at apple.com
Thu Nov 20 16:58:35 PST 2008


Author: kremenek
Date: Thu Nov 20 18:58:35 2008
New Revision: 59768

URL: http://llvm.org/viewvc/llvm-project?rev=59768&view=rev
Log:
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.

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=59768&r1=59767&r2=59768&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Thu Nov 20 18:58:35 2008
@@ -72,6 +72,8 @@
   
   /// AdvanceToken - Advances the PTHLexer to the next token.
   void AdvanceToken() { ++CurTokenIdx; }
+  
+  bool LexEndOfFile(Token &Result);
 };
 
 }  // end namespace clang

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=59768&r1=59767&r2=59768&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Thu Nov 20 18:58:35 2008
@@ -41,23 +41,17 @@
 
 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 @@
   }  
 }
 
+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];
 }





More information about the cfe-commits mailing list