Skip to content

Commit 220a969

Browse files
authored
[clang-doc] create namespace names according to their paths (llvm#162886)
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 3bca1e4 commit 220a969

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,20 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
584584
FileName = RecordSymbolInfo->MangledName;
585585
} else if (I->USR == GlobalNamespaceID)
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;
591597
}
592598

599+
// FIXME: Revert back to creating nested directories for namespaces instead of
600+
// putting everything in a flat directory structure.
593601
Error JSONGenerator::generateDocs(
594602
StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
595603
const ClangDocContext &CDCtx) {
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)