[cfe-commits] r42838 - /cfe/trunk/Driver/PrintPreprocessedOutput.cpp

Chris Lattner sabre at nondot.org
Wed Oct 10 13:45:17 PDT 2007


Author: lattner
Date: Wed Oct 10 15:45:16 2007
New Revision: 42838

URL: http://llvm.org/viewvc/llvm-project?rev=42838&view=rev
Log:
clang -E should not print tokens from the predefines buffer.

Modified:
    cfe/trunk/Driver/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=42838&r1=42837&r2=42838&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Wed Oct 10 15:45:16 2007
@@ -535,10 +535,16 @@
   
   // Start parsing the specified input file.
   PP.EnterMainSourceFile(MainFileID);
-  
-  do {
-    PrevTok = Tok;
-    PP.Lex(Tok);
+
+  // Consume all of the tokens that come from the predefines buffer.  Those
+  // should not be emitted into the output and are guaranteed to be at the
+  // start.
+  const SourceManager &SourceMgr = PP.getSourceManager();
+  do PP.Lex(Tok);
+  while (Tok.isNot(tok::eof) && 
+         !strcmp(SourceMgr.getSourceName(Tok.getLocation()), "<predefines>"));
+
+  while (1) {
     
     // If this token is at the start of a line, emit newlines if needed.
     if (Tok.isAtStartOfLine()) {
@@ -565,7 +571,12 @@
       OutputString(&S[0], S.size());
     }
     Callbacks->SetEmittedTokensOnThisLine();
-  } while (Tok.isNot(tok::eof));
+    
+    if (Tok.is(tok::eof)) break;
+   
+    PrevTok = Tok;
+    PP.Lex(Tok);
+  }
   OutputChar('\n');
   
   CleanupOutputBuffer();





More information about the cfe-commits mailing list