]> granicus.if.org Git - clang/commitdiff
PTHLexer:
authorTed Kremenek <kremenek@apple.com>
Fri, 21 Nov 2008 00:58:35 +0000 (00:58 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 21 Nov 2008 00:58:35 +0000 (00:58 +0000)
- 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

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

index 6f53c61750584f92d5b7914a5682f455b07eceac..3218a1dd5d60712bc785b704466b8ff46bb7645b 100644 (file)
@@ -72,6 +72,8 @@ private:
   
   /// AdvanceToken - Advances the PTHLexer to the next token.
   void AdvanceToken() { ++CurTokenIdx; }
+  
+  bool LexEndOfFile(Token &Result);
 };
 
 }  // end namespace clang
index a88470bbad69eeed5da14e4990537f67bf56bc53..5c6341f57dc74b1288c2dfb69e805fff582e5f40 100644 (file)
@@ -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];
 }