[cfe-commits] r38702 - in /cfe/cfe/trunk: Lex/Lexer.cpp Lex/Preprocessor.cpp include/clang/Lex/Lexer.h include/clang/Lex/Preprocessor.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:57 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:56 2007
New Revision: 38702

URL: http://llvm.org/viewvc/llvm-project?rev=38702&view=rev
Log:
Move Preprocessor::isNextPPTokenLParen to Lexer::isNextPPTokenLParen, where
it more rightly belongs.

Modified:
    cfe/cfe/trunk/Lex/Lexer.cpp
    cfe/cfe/trunk/Lex/Preprocessor.cpp
    cfe/cfe/trunk/include/clang/Lex/Lexer.h
    cfe/cfe/trunk/include/clang/Lex/Preprocessor.h

Modified: cfe/cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Lexer.cpp?rev=38702&r1=38701&r2=38702&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:23:56 2007
@@ -39,8 +39,7 @@
 
 Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp,
              const char *BufStart, const char *BufEnd)
-  : BufferPtr(BufStart ? BufStart : File->getBufferStart()),
-    BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
+  : BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
     InputFile(File), CurFileID(fileid), PP(pp), Features(PP.getLangOptions()) {
   Is_PragmaLexer = false;
   IsMainFile = false;
@@ -49,7 +48,9 @@
   assert(BufferEnd[0] == 0 &&
          "We assume that the input buffer has a null character at the end"
          " to simplify lexing!");
-      
+    
+  BufferPtr = BufStart ? BufStart : File->getBufferStart();
+
   // Start of the file is a start of line.
   IsAtStartOfLine = true;
 
@@ -922,6 +923,36 @@
   PP.HandleEndOfFile(Result);
 }
 
+/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
+/// the specified lexer will return a tok::l_paren token, 0 if it is something
+/// else and 2 if there are no more tokens in the buffer controlled by the
+/// lexer.
+unsigned Lexer::isNextPPTokenLParen() {
+  assert(!LexingRawMode && "How can we expand a macro from a skipping buffer?");
+  
+  // Switch to 'skipping' mode.  This will ensure that we can lex a token
+  // without emitting diagnostics, disables macro expansion, and will cause EOF
+  // to return an EOF token instead of popping the include stack.
+  LexingRawMode = true;
+  
+  // Save state that can be changed while lexing so that we can restore it.
+  const char *TmpBufferPtr = BufferPtr;
+  
+  LexerToken Tok;
+  Tok.StartToken();
+  LexTokenInternal(Tok);
+  
+  // Restore state that may have changed.
+  BufferPtr = TmpBufferPtr;
+  
+  // Restore the lexer back to non-skipping mode.
+  LexingRawMode = false;
+  
+  if (Tok.getKind() == tok::eof)
+    return 2;
+  return Tok.getKind() == tok::l_paren;
+}
+
 
 /// LexTokenInternal - This implements a simple C family lexer.  It is an
 /// extremely performance critical piece of code.  This assumes that the buffer

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38702&r1=38701&r2=38702&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:56 2007
@@ -506,37 +506,6 @@
   return true;
 }
 
-/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
-/// the specified lexer will return a tok::l_paren token, 0 if it is something
-/// else and 2 if there are no more tokens in the buffer controlled by the
-/// lexer.
-unsigned Preprocessor::isNextPPTokenLParen(Lexer *L) {
-  assert(!L->LexingRawMode &&
-         "How can we expand a macro from a skipping buffer?");
-  
-  // Set the lexer to 'skipping' mode.  This will ensure that we can lex a token
-  // without emitting diagnostics, disables macro expansion, and will cause EOF
-  // to return an EOF token instead of popping the include stack.
-  L->LexingRawMode = true;
-  
-  // Save state that can be changed while lexing so that we can restore it.
-  const char *BufferPtr = L->BufferPtr;
-  
-  LexerToken Tok;
-  Tok.StartToken();
-  L->LexTokenInternal(Tok);
-
-  // Restore state that may have changed.
-  L->BufferPtr = BufferPtr;
-  
-  // Restore the lexer back to non-skipping mode.
-  L->LexingRawMode = false;
-  
-  if (Tok.getKind() == tok::eof)
-    return 2;
-  return Tok.getKind() == tok::l_paren;
-}
-
 
 /// isNextPPTokenLParen - Determine whether the next preprocessor token to be
 /// lexed is a '('.  If so, consume the token and return true, if not, this
@@ -545,7 +514,7 @@
   // Do some quick tests for rejection cases.
   unsigned Val;
   if (CurLexer)
-    Val = isNextPPTokenLParen(CurLexer);
+    Val = CurLexer->isNextPPTokenLParen();
   else
     Val = CurMacroExpander->isNextTokenLParen();
   
@@ -555,7 +524,7 @@
     for (unsigned i = IncludeMacroStack.size(); Val == 2 && i != 0; --i) {
       IncludeStackInfo &Entry = IncludeMacroStack[i-1];
       if (Entry.TheLexer)
-        Val = isNextPPTokenLParen(Entry.TheLexer);
+        Val = Entry.TheLexer->isNextPPTokenLParen();
       else
         Val = Entry.TheMacroExpander->isNextTokenLParen();
     }

Modified: cfe/cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Lexer.h?rev=38702&r1=38701&r2=38702&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Lexer.h Wed Jul 11 11:23:56 2007
@@ -86,8 +86,9 @@
   bool LexingRawMode;
   
   //===--------------------------------------------------------------------===//
-  // Context that changes as the file is lexed.  NOTE: any state that mutates as
-  // the file is lexed should be added to Preprocessor::isNextPPTokenLParen.
+  // Context that changes as the file is lexed.
+  // NOTE: any state that mutates when in raw mode must have save/restore code
+  // in Lexer::isNextPPTokenLParen.
 
   // BufferPtr - Current pointer into the buffer.  This is the next character
   // to be lexed.
@@ -191,7 +192,11 @@
     BufferPtr = TokEnd;
   }
   
-  
+  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
+  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
+  /// tokens in the buffer controlled by this lexer.
+  unsigned isNextPPTokenLParen();
+
   //===--------------------------------------------------------------------===//
   // Lexer character reading interfaces.
   

Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38702&r1=38701&r2=38702&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:56 2007
@@ -466,12 +466,6 @@
   /// the macro should not be expanded return true, otherwise return false.
   bool HandleMacroExpandedIdentifier(LexerToken &Tok, MacroInfo *MI);
   
-  /// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
-  /// the specified lexer will return a tok::l_paren token, 0 if it is something
-  /// else and 2 if there are no more tokens in the buffer controlled by the
-  /// lexer.
-  unsigned isNextPPTokenLParen(Lexer *L);
-  
   /// isNextPPTokenLParen - Determine whether the next preprocessor token to be
   /// lexed is a '('.  If so, consume the token and return true, if not, this
   /// method should have no observable side-effect on the lexed tokens.





More information about the cfe-commits mailing list