[cfe-commits] r68640 - in /cfe/trunk: lib/Lex/PPDirectives.cpp test/Preprocessor/include-macros.c tools/clang-cc/clang-cc.cpp

Chris Lattner sabre at nondot.org
Wed Apr 8 13:53:25 PDT 2009


Author: lattner
Date: Wed Apr  8 15:53:24 2009
New Revision: 68640

URL: http://llvm.org/viewvc/llvm-project?rev=68640&view=rev
Log:
finish the implementation of -imacros.  The driver still needs to be hooked up.

Added:
    cfe/trunk/test/Preprocessor/include-macros.c
Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

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

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Apr  8 15:53:24 2009
@@ -1050,8 +1050,7 @@
     return;
   }
   
-  // Verify that there is nothing after the filename, other than EOM.  Use the
-  // preprocessor to lex this in case lexing the filename entered a macro.
+  // Verify that there is nothing after the filename, other than EOM.
   CheckEndOfDirective("#include");
 
   // Check that we don't have infinite #include recursion.
@@ -1141,8 +1140,15 @@
     return;
   }
   
-  // TODO: implement me :)
-  DiscardUntilEndOfDirective();
+  // Treat this as a normal #include for checking purposes.  If this is
+  // successful, it will push a new lexer onto the include stack.
+  HandleIncludeDirective(IncludeMacrosTok, 0, false);
+  
+  Token TmpTok;
+  do {
+    Lex(TmpTok);
+    assert(TmpTok.isNot(tok::eof) && "Didn't find end of -imacros!");
+  } while (TmpTok.isNot(tok::hashhash));
 }
 
 //===----------------------------------------------------------------------===//

Added: cfe/trunk/test/Preprocessor/include-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-macros.c?rev=68640&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/include-macros.c (added)
+++ cfe/trunk/test/Preprocessor/include-macros.c Wed Apr  8 15:53:24 2009
@@ -0,0 +1,4 @@
+// RUN: clang-cc -E -Dtest=FOO -imacros pr2086.h %s | grep 'HERE: test'
+
+// This should not be expanded into FOO because pr2086.h undefs 'test'.
+HERE: test

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68640&r1=68639&r2=68640&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Apr  8 15:53:24 2009
@@ -1029,6 +1029,9 @@
   Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end());
   Buf.push_back('"');
   Buf.push_back('\n');
+  // Marker token to stop the __include_macros fetch loop.
+  const char *Marker = "##\n"; // ##?
+  Buf.insert(Buf.end(), Marker, Marker+strlen(Marker));
 }
 
 /// AddImplicitIncludePTH - Add an implicit #include using the original file





More information about the cfe-commits mailing list