]> granicus.if.org Git - clang/commitdiff
Rewrote PTHLexer::Lex by digging through the sources of Lexer again. Now we can...
authorTed Kremenek <kremenek@apple.com>
Thu, 20 Nov 2008 07:58:05 +0000 (07:58 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 20 Nov 2008 07:58:05 +0000 (07:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59724 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PTHLexer.cpp

index 936a03ac0f0aa151a25f57a7e61ea44bc06a059b..4e975d9f4865a5917ffcb837dabd6077ef1c6069 100644 (file)
@@ -23,51 +23,60 @@ PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc,
     LastToken(NumTokens - 1),
     CurToken(0) {
 
-  assert (NumTokens >= 1);
-  assert (Tokens[LastToken].is(tok::eof));
+  assert(NumTokens >= 1);
+  assert(Tokens[LastToken].is(tok::eof));
 }
 
 void PTHLexer::Lex(Token& Tok) {
-
-  if (CurToken == LastToken) {    
-    // 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.
-    //   OR
-    // If we are in raw mode, return this event as an EOF token.  Let the caller
-    // that put us in raw mode handle the event.
-    if (ParsingPreprocessorDirective || LexingRawMode) {
-      // Done parsing the "line".
+LexNextToken:
+  if (CurToken == LastToken) {
+    if (ParsingPreprocessorDirective) {
       ParsingPreprocessorDirective = false;
-      Tok = Tokens[CurToken]; // not an out-of-bound access
-      // FIXME: eom handling?
+      Tok = Tokens[LastToken];
+      Tok.setKind(tok::eom);
+      MIOpt.ReadToken();
+      return;
     }
-    else
-      PP->HandleEndOfFile(Tok, false);
     
+    assert(!LexingRawMode && "PTHLexer cannot lex in raw mode.");
+    
+    // FIXME: Issue diagnostics similar to Lexer.
+    PP->HandleEndOfFile(Tok, false);    
     return;
   }
 
   Tok = Tokens[CurToken];
   
-  if (ParsingPreprocessorDirective && Tok.isAtStartOfLine()) {
-    ParsingPreprocessorDirective = false; // Done parsing the "line".
+  // 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
+  // consume this token twice, once as an tok::eom.
+  if (Tok.isAtStartOfLine() && ParsingPreprocessorDirective) {
+    ParsingPreprocessorDirective = false;
+    Tok.setKind(tok::eom);
     MIOpt.ReadToken();
-    // FIXME:  Need to replicate:
-    // FormTokenWithChars(Tok, CurPtr, tok::eom);
-    Tok.setKind(tok::eom);    
     return;
   }
-  else // Otherwise, advance to the next token.
-    ++CurToken;
+  
+  // Advance to the next token.
+  ++CurToken;
+    
+  if (Tok.is(tok::hash)) {    
+    if (Tok.isAtStartOfLine() && !LexingRawMode) {
+      PP->HandleDirective(Tok);
 
-  if (Tok.isAtStartOfLine() && Tok.is(tok::hash) && !LexingRawMode) {
-    PP->HandleDirective(Tok);
-    PP->Lex(Tok);
-    return;
+      if (PP->isCurrentLexer(this))
+        goto LexNextToken;
+
+      return PP->Lex(Tok);
+    }
   }
-    
+
   MIOpt.ReadToken();
+  
+  if (Tok.is(tok::identifier)) {
+    if (LexingRawMode) return;
+    return PP->HandleIdentifier(Tok);
+  }  
 }
 
 void PTHLexer::setEOF(Token& Tok) {