[clang-tools-extra] 3af43e3 - [clang-doc] simplify filename selection for namespaces (#162885)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 10 13:34:16 PDT 2025
Author: Erick Velez
Date: 2025-10-10T13:34:11-07:00
New Revision: 3af43e303ce74a3df6e3349a50ecdb501f559b26
URL: https://github.com/llvm/llvm-project/commit/3af43e303ce74a3df6e3349a50ecdb501f559b26
DIFF: https://github.com/llvm/llvm-project/commit/3af43e303ce74a3df6e3349a50ecdb501f559b26.diff
LOG: [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.
Added:
Modified:
clang-tools-extra/clang-doc/JSONGenerator.cpp
clang-tools-extra/clang-doc/Representation.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 26794a5e34d02..6fba2114b8c38 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -582,11 +582,10 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
if (I->IT == InfoType::IT_record) {
auto *RecordSymbolInfo = static_cast<SymbolInfo *>(I);
FileName = RecordSymbolInfo->MangledName;
- } else if (I->IT == InfoType::IT_namespace && I->Name != "")
- // Serialize the global namespace as index.json
- FileName = I->Name;
+ } else if (I->USR == GlobalNamespaceID)
+ FileName = "index";
else
- FileName = I->getFileBaseName();
+ FileName = I->Name;
sys::path::append(Path, FileName + ".json");
return FileName;
}
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 2a75f89696b7d..d8c2b9c0a5842 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -30,6 +30,9 @@ namespace doc {
// SHA1'd hash of a USR.
using SymbolID = std::array<uint8_t, 20>;
+constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
struct BaseRecordInfo;
struct EnumInfo;
struct FunctionInfo;
More information about the cfe-commits
mailing list