[cfe-commits] r38609 - 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:10 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:10 2007
New Revision: 38609

URL: http://llvm.org/viewvc/llvm-project?rev=38609&view=rev
Log:
Fix some minor bugs handling _Pragma, including
test/Preprocessor/_Pragma_syshdr.c

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=38609&r1=38608&r2=38609&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:23:10 2007
@@ -43,6 +43,7 @@
     BufferStart(BufferPtr),
     BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
     InputFile(File), CurFileID(fileid), PP(pp), Features(PP.getLangOptions()) {
+  Is_PragmaLexer = false;
   InitCharacterInfo();
       
   assert(BufferEnd[0] == 0 &&

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

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:10 2007
@@ -348,6 +348,39 @@
   return 0;
 }
 
+/// isInPrimaryFile - Return true if we're in the top-level file, not in a
+/// #include.
+bool Preprocessor::isInPrimaryFile() const {
+  unsigned NumLexersFound = 0;
+  if (CurLexer && !CurLexer->Is_PragmaLexer)
+    ++NumLexersFound;
+  
+  /// If there are any stacked lexers, we're in a #include.
+  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i)
+    if (IncludeMacroStack[i].TheLexer) {
+      if (!IncludeMacroStack[i].TheLexer->Is_PragmaLexer)
+        if (++NumLexersFound > 1)
+          return false;
+    }
+  return NumLexersFound < 2;
+}
+
+/// getCurrentLexer - Return the current file lexer being lexed from.  Note
+/// that this ignores any potentially active macro expansions and _Pragma
+/// expansions going on at the time.
+Lexer *Preprocessor::getCurrentFileLexer() const {
+  if (CurLexer && !CurLexer->Is_PragmaLexer) return CurLexer;
+  
+  // Look for a stacked lexer.
+  for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {
+    Lexer *L = IncludeMacroStack[i].TheLexer;
+    if (L && !L->Is_PragmaLexer) // Ignore macro & _Pragma expansions.
+      return L;
+  }
+  return 0;
+}
+
+
 /// EnterSourceFile - Add a source file to the top of the include stack and
 /// start lexing tokens from it instead of the current buffer.  Return true
 /// on failure.
@@ -630,7 +663,7 @@
     // Get the file that we are lexing out of.  If we're currently lexing from
     // a macro, dig into the include stack.
     const FileEntry *CurFile = 0;
-    Lexer *TheLexer = getCurrentLexer();
+    Lexer *TheLexer = getCurrentFileLexer();
     
     if (TheLexer)
       CurFile = SourceMgr.getFileEntryForFileID(TheLexer->getCurFileID());
@@ -1510,6 +1543,9 @@
   // return an EOM token.
   TL->ParsingPreprocessorDirective = true;
   
+  // This lexer really is for _Pragma.
+  TL->Is_PragmaLexer = true;
+  
   // With everything set up, lex this as a #pragma directive.
   HandlePragmaDirective();
   
@@ -1619,7 +1655,7 @@
   if (File == 0)
     return Diag(FilenameTok, diag::err_pp_file_not_found);
   
-  Lexer *TheLexer = getCurrentLexer();
+  Lexer *TheLexer = getCurrentFileLexer();
   const FileEntry *CurFile =
     SourceMgr.getFileEntryForFileID(TheLexer->getCurFileID());
 

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=38609&r1=38608&r2=38609&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Lexer.h Wed Jul 11 11:23:10 2007
@@ -58,6 +58,7 @@
   unsigned CurFileID;            // FileID for the current input file.
   Preprocessor &PP;              // Preprocessor object controlling lexing.
   LangOptions Features;          // Features enabled by this language (cache).
+  bool Is_PragmaLexer;           // True if lexer for _Pragma handling.
   
   // Context-specific lexing flags.
   bool IsAtStartOfLine;          // True if sitting at start of line.

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=38609&r1=38608&r2=38609&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:10 2007
@@ -212,26 +212,13 @@
   
   /// isInPrimaryFile - Return true if we're in the top-level file, not in a
   /// #include.
-  ///
-  bool isInPrimaryFile() const {
-    /// If there are any stacked lexers, we're in a #include.
-    for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i)
-      if (IncludeMacroStack[i].TheLexer)
-        return false;
-    return true;
-  }
+  bool isInPrimaryFile() const;
+  
+  /// getCurrentLexer - Return the current file lexer being lexed from.  Note
+  /// that this ignores any potentially active macro expansions and _Pragma
+  /// expansions going on at the time.
+  Lexer *getCurrentFileLexer() const;
   
-  /// getCurrentLexer - Return the current lexer being lexed from.  Note that
-  /// this ignores any potentially active macro expansions going on at the time.
-  Lexer *getCurrentLexer() const {
-    if (CurLexer) return CurLexer;
-    
-    // Look for a stacked lexer.
-    for (unsigned i = IncludeMacroStack.size(); i != 0; --i)
-      if (IncludeMacroStack[i].TheLexer)  // Ignore macro expansions.
-        return IncludeMacroStack[i].TheLexer;
-    return 0;
-  }
   
   /// SetSearchPaths - Interface for setting the file search paths.
   ///





More information about the cfe-commits mailing list