Skip to content

Commit 3af43e3

Browse files
authored
[clang-doc] simplify filename selection for namespaces (#162885)
determineFileName was confusing regarding namespaces. The comment and conditional were both misleading. Now, we just check against a static global namespace USR to make a file use "index", or just use the name.
1 parent 9f0f6e8 commit 3af43e3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,10 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
582582
if (I->IT == InfoType::IT_record) {
583583
auto *RecordSymbolInfo = static_cast<SymbolInfo *>(I);
584584
FileName = RecordSymbolInfo->MangledName;
585-
} else if (I->IT == InfoType::IT_namespace && I->Name != "")
586-
// Serialize the global namespace as index.json
587-
FileName = I->Name;
585+
} else if (I->USR == GlobalNamespaceID)
586+
FileName = "index";
588587
else
589-
FileName = I->getFileBaseName();
588+
FileName = I->Name;
590589
sys::path::append(Path, FileName + ".json");
591590
return FileName;
592591
}

clang-tools-extra/clang-doc/Representation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ namespace doc {
3030
// SHA1'd hash of a USR.
3131
using SymbolID = std::array<uint8_t, 20>;
3232

33+
constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
35+
3336
struct BaseRecordInfo;
3437
struct EnumInfo;
3538
struct FunctionInfo;

0 commit comments

Comments
 (0)