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

Ted Kremenek kremenek at apple.com
Tue Dec 23 11:24:45 PST 2008


Author: kremenek
Date: Tue Dec 23 13:24:24 2008
New Revision: 61381

URL: http://llvm.org/viewvc/llvm-project?rev=61381&view=rev
Log:
PTH: Remove some methods and simplify some conditions in PTHLexer::Lex().  No big functionality change.

Modified:
    cfe/trunk/include/clang/Lex/PTHLexer.h
    cfe/trunk/lib/Lex/PPLexerChange.cpp
    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=61381&r1=61380&r2=61381&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Tue Dec 23 13:24:24 2008
@@ -64,7 +64,7 @@
   /// Lex - Return the next token.
   void Lex(Token &Tok);
   
-  void setEOF(Token &Tok);
+  void getEOF(Token &Tok);
   
   /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
   /// uninterpreted string.  This switches the lexer out of directive mode.
@@ -92,9 +92,6 @@
 
   /// SkipBlock - Used by Preprocessor to skip the current conditional block.
   bool SkipBlock();
-
-private:
-  bool LexEndOfFile(Token &Result);
 };
 
 }  // end namespace clang

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

==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Tue Dec 23 13:24:24 2008
@@ -308,7 +308,7 @@
     CurLexer.reset();
   }
   else {
-    CurPTHLexer->setEOF(Result);
+    CurPTHLexer->getEOF(Result);
     CurPTHLexer.reset();
   }
   

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

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Tue Dec 23 13:24:24 2008
@@ -87,7 +87,8 @@
   
   Tok.startToken();
   Tok.setKind(k);
-  Tok.setFlag(flags);     
+  Tok.setFlag(flags);
+  assert(!LexingRawMode);
   Tok.setIdentifierInfo(perID ? PTHMgr.GetIdentifierInfo(perID-1) : 0);
   Tok.setLocation(SourceLocation::getFileLoc(FileID, FileOffset));
   Tok.setLength(Len);
@@ -96,80 +97,51 @@
   // Process the token.
   //===--------------------------------------==//
 
-  if (Tok.is(tok::eof)) {
+  if (k == tok::identifier) {
+    MIOpt.ReadToken();
+    return PP->HandleIdentifier(Tok);
+  }
+  
+  if (k == tok::eof) {
     // Save the end-of-file token.
     EofToken = Tok;
     
     Preprocessor *PPCache = PP;
-
-    if (LexEndOfFile(Tok))
+    
+    assert(!ParsingPreprocessorDirective);
+    assert(!LexingRawMode);
+    
+    // FIXME: Issue diagnostics similar to Lexer.
+    if (PP->HandleEndOfFile(Tok, false))
       return;
-
+    
     assert(PPCache && "Raw buffer::LexEndOfFile should return a token");
     return PPCache->Lex(Tok);
   }
-
-  MIOpt.ReadToken();
-  
-  if (Tok.is(tok::eom)) {
-    ParsingPreprocessorDirective = false;
-    return;
-  }
   
-#if 0
-  SourceManager& SM = PP->getSourceManager();
-  SourceLocation L = Tok.getLocation();
-  
-  static const char* last = 0;
-  const char* next = SM.getContentCacheForLoc(L)->Entry->getName();
-  if (next != last) {
-    last = next;
-    llvm::cerr << next << '\n';
-  }
-
-  llvm::cerr << "line " << SM.getLogicalLineNumber(L) << " col " <<
-  SM.getLogicalColumnNumber(L) << '\n';
-#endif
-    
-  if (Tok.is(tok::hash)) {    
-    if (Tok.isAtStartOfLine()) {
-      LastHashTokPtr = CurPtr - DISK_TOKEN_SIZE;
-      if (!LexingRawMode) {
-        PP->HandleDirective(Tok);
-
-        if (PP->isCurrentLexer(this))
-          goto LexNextToken;
-        
-        return PP->Lex(Tok);
-      }
-    }
-  }
-  
-  if (Tok.is(tok::identifier)) {
-    if (LexingRawMode) {
-      Tok.setIdentifierInfo(0);
-      return;
-    }
+  if (k == tok::hash && Tok.isAtStartOfLine()) {
+    LastHashTokPtr = CurPtr - DISK_TOKEN_SIZE;
+    assert(!LexingRawMode);
+    PP->HandleDirective(Tok);
     
-    return PP->HandleIdentifier(Tok);
+    if (PP->isCurrentLexer(this))
+      goto LexNextToken;
+    
+    return PP->Lex(Tok);
   }
-
   
-  assert(!Tok.is(tok::eom) || ParsingPreprocessorDirective);
-}
+  if (k == tok::eom) {
+    assert(ParsingPreprocessorDirective);
+    ParsingPreprocessorDirective = false;
+    return;
+  }
 
-// FIXME: This method can just be inlined into Lex().
-bool PTHLexer::LexEndOfFile(Token &Tok) {
-  assert(!ParsingPreprocessorDirective);
-  assert(!LexingRawMode);
-  
-  // FIXME: Issue diagnostics similar to Lexer.
-  return PP->HandleEndOfFile(Tok, false);
+  MIOpt.ReadToken();
 }
 
 // FIXME: We can just grab the last token instead of storing a copy
 // into EofToken.
-void PTHLexer::setEOF(Token& Tok) {
+void PTHLexer::getEOF(Token& Tok) {
   assert(!EofToken.is(tok::eof));
   Tok = EofToken;
 }
@@ -304,7 +276,7 @@
   // handling a #included file.  Just read the necessary data from the token
   // data buffer to construct the SourceLocation object.
   // NOTE: This is a virtual function; hence it is defined out-of-line.
-  const char* p = CurPtr + (1 + 1 + 4);
+  const char* p = CurPtr + (1 + 1 + 3);
   uint32_t offset = 
        ((uint32_t) ((uint8_t) p[0]))
     | (((uint32_t) ((uint8_t) p[1])) << 8)





More information about the cfe-commits mailing list