[cfe-commits] r72724 - in /cfe/trunk: lib/Frontend/PrintPreprocessedOutput.cpp test/Preprocessor/dump-macros-spacing.c

Eli Friedman eli.friedman at gmail.com
Tue Jun 2 00:55:40 PDT 2009


Author: efriedma
Date: Tue Jun  2 02:55:39 2009
New Revision: 72724

URL: http://llvm.org/viewvc/llvm-project?rev=72724&view=rev
Log:
PR4288: Make -dD (dump macros with preprocessed source) play nicely with 
# line directives.


Added:
    cfe/trunk/test/Preprocessor/dump-macros-spacing.c
Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=72724&r1=72723&r2=72724&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Tue Jun  2 02:55:39 2009
@@ -87,6 +87,7 @@
 private:
   unsigned CurLine;
   bool EmittedTokensOnThisLine;
+  bool EmittedMacroOnThisLine;
   SrcMgr::CharacteristicKind FileType;
   llvm::SmallString<512> CurFilename;
   bool Initialized;
@@ -100,6 +101,7 @@
     CurLine = 0;
     CurFilename += "<uninit>";
     EmittedTokensOnThisLine = false;
+    EmittedMacroOnThisLine = false;
     FileType = SrcMgr::C_User;
     Initialized = false;
   }
@@ -130,9 +132,10 @@
 void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
                                              const char *Extra,
                                              unsigned ExtraLen) {
-  if (EmittedTokensOnThisLine) {
+  if (EmittedTokensOnThisLine || EmittedMacroOnThisLine) {
     OS << '\n';
     EmittedTokensOnThisLine = false;
+    EmittedMacroOnThisLine = false;
   }
 
   OS << '#' << ' ' << LineNo << ' ' << '"';
@@ -161,11 +164,12 @@
     
     CurLine = LineNo;
     
-    if (!EmittedTokensOnThisLine)
+    if (!EmittedTokensOnThisLine && !EmittedMacroOnThisLine)
       return true;
     
     OS << '\n';
     EmittedTokensOnThisLine = false;
+    EmittedMacroOnThisLine = false;
     return true;
   }
 
@@ -260,6 +264,7 @@
   
   MoveToLine(MI->getDefinitionLoc());
   PrintMacroDefinition(*II, *MI, PP, OS);
+  EmittedMacroOnThisLine = true;
 }
 
 

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

==============================================================================
--- cfe/trunk/test/Preprocessor/dump-macros-spacing.c (added)
+++ cfe/trunk/test/Preprocessor/dump-macros-spacing.c Tue Jun  2 02:55:39 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -E -dD < %s | grep stdin | grep -v define
+#define A A
+/* 1
+ * 2
+ * 3
+ * 4
+ * 5
+ * 6
+ * 7
+ * 8
+ */
+#define B B
+





More information about the cfe-commits mailing list