[llvm-branch-commits] [clang-tools-extra] [clang-doc] create namespace names according to their paths (PR #162886)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 10 10:01:23 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Erick Velez (evelez7)
<details>
<summary>Changes</summary>
Namespace filenames didn't consider their paths, so foo::tools would use
the same file as bar::tools. Now we consider their paths to avoid that
problem.
---
Full diff: https://github.com/llvm/llvm-project/pull/162886.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+7-1)
- (added) clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp (+20)
- (modified) clang-tools-extra/test/clang-doc/json/nested-namespace.cpp (+1-1)
``````````diff
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 1b08b1791b6eb..df816d78d77fe 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -584,7 +584,13 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
FileName = RecordSymbolInfo->MangledName;
} else if (I->USR == GlobalNamespace)
FileName = "index";
- else
+ else if (I->IT == InfoType::IT_namespace) {
+ for (const auto &NS : I->Namespace) {
+ FileName += NS.Name;
+ FileName += "_";
+ }
+ FileName += I->Name;
+ } else
FileName = I->Name;
sys::path::append(Path, FileName + ".json");
return FileName;
diff --git a/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
new file mode 100644
index 0000000000000..04fcfc1dc0a85
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: FileCheck %s < %t/json/foo_tools.json --check-prefix=CHECK-FOO
+// RUN: FileCheck %s < %t/json/bar_tools.json --check-prefix=CHECK-BAR
+
+namespace foo {
+ namespace tools {
+ class FooTools {};
+ } // namespace tools
+} // namespace foo
+
+namespace bar {
+ namespace tools {
+ class BarTools {};
+ } // namespace tools
+} // namespace bar
+
+// CHECK-FOO: "Name": "tools"
+
+// CHECK-BAR: "Name": "tools"
diff --git a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
index b19afc1885104..cf19e1e34a818 100644
--- a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED
-// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER
+// RUN: FileCheck %s < %t/json/nested_inner.json --check-prefix=INNER
namespace nested {
int Global;
``````````
</details>
https://github.com/llvm/llvm-project/pull/162886
More information about the llvm-branch-commits
mailing list