[PATCH] D52847: [clang-doc] Handle anonymous namespaces

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 3 15:34:37 PDT 2018


leonardchan added inline comments.


================
Comment at: clang-tools-extra/clang-doc/Representation.cpp:193-216
+llvm::SmallString<16> Info::extractFileName() {
+  switch (IT) {
+  case InfoType::IT_namespace:
+    // The case of anonymous namespaces is taken care of in serialization, so
+    // here we can safely assume an unnamed namespace is the global one.
+    return Name.empty() ? llvm::SmallString<16>("GlobalNamespace") : Name;
+  case InfoType::IT_record:
----------------
Nit: Check for `Name.empty()` early and return `Name` if it is empty, then have the switch stmt to avoid the repeated conditional expressions.

```
if (!Name.empty())
  return Name

switch () {
  case InfoType::IT_namespace:
    return llvm::SmallString<16>("GlobalNamespace");
  ...
}
```


================
Comment at: clang-tools-extra/clang-doc/Serialize.cpp:280
+      } else
+        N->getNameAsString();
+      Namespaces.emplace_back(getUSRForDecl(N), Namespace,
----------------
Should this line be `Namespace = N->getNameAsString()`?


https://reviews.llvm.org/D52847





More information about the cfe-commits mailing list