Skip to content

Conversation

evelez7
Copy link
Member

@evelez7 evelez7 commented Oct 10, 2025

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.

Copy link
Member Author

evelez7 commented Oct 10, 2025

@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Erick Velez (evelez7)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/162885.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+3-4)
  • (modified) clang-tools-extra/clang-doc/Representation.h (+3)
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 26794a5e34d02..1b08b1791b6eb 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 == GlobalNamespace)
+    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..4dd7ce86b9304 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>;
 
+static const SymbolID GlobalNamespace = {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;

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.
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-fix-index-filename branch from b345c72 to 17048c0 Compare October 10, 2025 19:19
@evelez7 evelez7 requested a review from ilovepi October 10, 2025 19:19
Copy link
Member Author

evelez7 commented Oct 10, 2025

Merge activity

  • Oct 10, 8:31 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 10, 8:34 PM UTC: @evelez7 merged this pull request with Graphite.

@evelez7 evelez7 merged commit 3af43e3 into main Oct 10, 2025
10 checks passed
@evelez7 evelez7 deleted the users/evelez7/clang-doc-fix-index-filename branch October 10, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants