Skip to content

Commit 420db87

Browse files
committed
[clang-doc] create namespace names according to their paths
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.
1 parent b345c72 commit 420db87

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

clang-tools-extra/clang-doc/JSONGenerator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,13 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
584584
FileName = RecordSymbolInfo->MangledName;
585585
} else if (I->USR == GlobalNamespace)
586586
FileName = "index";
587-
else
587+
else if (I->IT == InfoType::IT_namespace) {
588+
for (const auto &NS : I->Namespace) {
589+
FileName += NS.Name;
590+
FileName += "_";
591+
}
592+
FileName += I->Name;
593+
} else
588594
FileName = I->Name;
589595
sys::path::append(Path, FileName + ".json");
590596
return FileName;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
3+
// RUN: FileCheck %s < %t/json/foo_tools.json --check-prefix=CHECK-FOO
4+
// RUN: FileCheck %s < %t/json/bar_tools.json --check-prefix=CHECK-BAR
5+
6+
namespace foo {
7+
namespace tools {
8+
class FooTools {};
9+
} // namespace tools
10+
} // namespace foo
11+
12+
namespace bar {
13+
namespace tools {
14+
class BarTools {};
15+
} // namespace tools
16+
} // namespace bar
17+
18+
// CHECK-FOO: "Name": "tools"
19+
20+
// CHECK-BAR: "Name": "tools"

clang-tools-extra/test/clang-doc/json/nested-namespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
33
// RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED
4-
// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER
4+
// RUN: FileCheck %s < %t/json/nested_inner.json --check-prefix=INNER
55

66
namespace nested {
77
int Global;

0 commit comments

Comments
 (0)