]> granicus.if.org Git - clang/commitdiff
clang-format: Understand #pragma mark
authorDaniel Jasper <djasper@google.com>
Thu, 9 Jan 2014 13:56:49 +0000 (13:56 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 9 Jan 2014 13:56:49 +0000 (13:56 +0000)
Before:
  #pragma mark Any non - hyphenated or hyphenated string(including parentheses).
After:
  #pragma mark Any non-hyphenated or hyphenated string (including parentheses).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198870 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 98cc00334291c0accd79a505c1c4fc477a12a019..1268be29b3c36d65f29efe24d66b2cf8da16a8d6 100644 (file)
@@ -474,6 +474,18 @@ private:
     }
   }
 
+  void parsePragma() {
+    next(); // Consume "pragma".
+    if (CurrentToken && CurrentToken->TokenText == "mark") {
+      next(); // Consume "mark".
+      next(); // Consume first token (so we fix leading whitespace).
+      while (CurrentToken != NULL) {
+        CurrentToken->Type = TT_ImplicitStringLiteral;
+        next();
+      }
+    }
+  }
+
   void parsePreprocessorDirective() {
     next();
     if (CurrentToken == NULL)
@@ -495,6 +507,9 @@ private:
     case tok::pp_warning:
       parseWarningOrError();
       break;
+    case tok::pp_pragma:
+      parsePragma();
+      break;
     case tok::pp_if:
     case tok::pp_elif:
       parseLine();
index 432caf47741269566788d727ca4b4e021b2b4e17..22b27037cfd3757d7d156a147a8eabac2e5ef5d3 100644 (file)
@@ -7177,6 +7177,11 @@ TEST_F(FormatTest, CatchExceptionReferenceBinding) {
 TEST_F(FormatTest, UnderstandsPragmas) {
   verifyFormat("#pragma omp reduction(| : var)");
   verifyFormat("#pragma omp reduction(+ : var)");
+
+  EXPECT_EQ("#pragma mark Any non-hyphenated or hyphenated string "
+            "(including parentheses).",
+            format("#pragma    mark   Any non-hyphenated or hyphenated string "
+                   "(including parentheses)."));
 }
 
 #define EXPECT_ALL_STYLES_EQUAL(Styles)                                        \