[PATCH] Recognize function-like macro usages without semicolon in declaration context.

Alexander Kornienko alexfh at google.com
Mon Apr 8 06:59:29 PDT 2013


Hi djasper, klimek,

Preserve line breaks after function-like macro usages without
semicolon, e.g.:

QQQ(xxx)
class X {
};

http://llvm-reviews.chandlerc.com/D638

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -266,6 +266,7 @@
   switch (FormatTok.Tok.getKind()) {
   case tok::at:
     nextToken();
+    ++TokenNumber;
     if (FormatTok.Tok.is(tok::l_brace)) {
       parseBracedList();
       break;
@@ -297,7 +298,7 @@
     return;
   case tok::kw_inline:
     nextToken();
-    TokenNumber++;
+    ++TokenNumber;
     if (FormatTok.Tok.is(tok::kw_namespace)) {
       parseNamespace();
       return;
@@ -388,6 +389,17 @@
         parseLabel();
         return;
       }
+      // Recognize function-like macro usages without trailing semicolon in
+      // declaration context.
+      if (TokenNumber == 1 && FormatTok.Tok.is(tok::l_paren)) {
+        parseParens();
+        if (Line->MustBeDeclaration &&
+            ((FormatTok.NewlinesBefore > 0 && FormatTok.HasUnescapedNewline) ||
+             FormatTok.IsFirst)) {
+          addUnwrappedLine();
+          return;
+        }
+      }
       break;
     case tok::equal:
       nextToken();
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1335,6 +1335,22 @@
                "f(STR(this_is_a_string_literal{));");
 }
 
+TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {
+  EXPECT_EQ("INITIALIZE_PASS_BEGIN(ScopDetection, \"polly-detect\")\n"
+            "INITIALIZE_AG_DEPENDENCY(AliasAnalysis)\n"
+            "INITIALIZE_PASS_DEPENDENCY(DominatorTree)\n"
+            "class X {\n"
+            "};\n"
+            "INITIALIZE_PASS_END(ScopDetection, \"polly-detect\")\n"
+            "int *createScopDetectionPass() { return 0; }",
+            format("  INITIALIZE_PASS_BEGIN(ScopDetection, \"polly-detect\")\n"
+                   "  INITIALIZE_AG_DEPENDENCY(AliasAnalysis)\n"
+                   "  INITIALIZE_PASS_DEPENDENCY(DominatorTree)\n"
+                   "  class X {};\n"
+                   "  INITIALIZE_PASS_END(ScopDetection, \"polly-detect\")\n"
+                   "  int *createScopDetectionPass() { return 0; }"));
+}
+
 TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
   EXPECT_EQ("{\n  {\n#define A\n  }\n}", format("{{\n#define A\n}}"));
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D638.1.patch
Type: text/x-patch
Size: 2365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130408/d2ffd5a9/attachment.bin>


More information about the cfe-commits mailing list