[PATCH] D51036: clang-format: Fix formatting C++ namespaces with preceding 'inline' or 'export' specifier

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 21 11:21:15 PDT 2018


owenpan requested changes to this revision.
owenpan added a comment.
This revision now requires changes to proceed.

By the way, I didn't review the test cases.



================
Comment at: lib/Format/FormatToken.h:524-525
+    // Detect "(inline|export)? namespace" in the beginning of a line.
+    if (NamespaceTok &&
+        (NamespaceTok->is(tok::kw_inline) || NamespaceTok->is(tok::kw_export)))
       NamespaceTok = NamespaceTok->getNextNonComment();
----------------
```
    if (NamespaceTok && NamespaceTok->isOneOf(tok::kw_inline, tok::kw_export))
```


================
Comment at: lib/Format/NamespaceEndCommentsFixer.cpp:128-133
+  // Detect "(inline|export)? namespace" in the beginning of a line.
+  if (NamespaceTok->is(tok::kw_inline) || NamespaceTok->is(tok::kw_export))
     NamespaceTok = NamespaceTok->getNextNonComment();
   if (!NamespaceTok || NamespaceTok->isNot(tok::kw_namespace))
     return nullptr;
   return NamespaceTok;
----------------
These lines are functionally the same as lines 523-528 in FormatToken.h. Refactor them?


================
Comment at: lib/Format/NamespaceEndCommentsFixer.cpp:129-130
+  // Detect "(inline|export)? namespace" in the beginning of a line.
+  if (NamespaceTok->is(tok::kw_inline) || NamespaceTok->is(tok::kw_export))
     NamespaceTok = NamespaceTok->getNextNonComment();
   if (!NamespaceTok || NamespaceTok->isNot(tok::kw_namespace))
----------------
```
  if (NamespaceTok && NamespaceTok->isOneOf(tok::kw_inline, tok::kw_export))
```


================
Comment at: lib/Format/UnwrappedLineParser.cpp:992-998
   case tok::kw_inline:
     nextToken();
     if (FormatTok->Tok.is(tok::kw_namespace)) {
       parseNamespace();
       return;
     }
     break;
----------------
Move this case to after the case tok::kw_export below.


================
Comment at: lib/Format/UnwrappedLineParser.cpp:1066-1072
+    if (Style.isCpp()) {
+      nextToken();
+      if (FormatTok->Tok.is(tok::kw_namespace)) {
+        parseNamespace();
+        return;
+      }
+    }
----------------
```
    if (!Style.isCpp())
      break;
  case tok::kw_inline:
    nextToken();
    if (FormatTok->Tok.is(tok::kw_namespace)) {
      parseNamespace();
      return;
    }
```


Repository:
  rC Clang

https://reviews.llvm.org/D51036





More information about the cfe-commits mailing list