Skip to content

Commit f6c04cd

Browse files
authored
[clang-doc] Serialize the global namespace name in JSON (#171701)
Previously, the global namespace's "Name" field was left empty. It could be identified this way, but it could also be identified by its USR. Actually populating the "Name" field allows for nicer output in the future.
1 parent 5e3549a commit f6c04cd

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ static void serializeInfo(const VarInfo &I, json::Object &Obj,
610610
static void serializeInfo(const NamespaceInfo &I, json::Object &Obj,
611611
const std::optional<StringRef> RepositoryUrl) {
612612
serializeCommonAttributes(I, Obj, RepositoryUrl);
613+
if (I.USR == GlobalNamespaceID)
614+
Obj["Name"] = "Global Namespace";
613615

614616
if (!I.Children.Namespaces.empty())
615617
serializeArray(I.Children.Namespaces, Obj, "Namespaces",

clang-tools-extra/clang-doc/assets/namespace-template.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<main>
1414
<div class="container">
1515
<div class="sidebar">
16-
<h2>{{RecordType}} {{Name}}</h2>
16+
<h2>{{#RecordType}}{{RecordType}} {{/RecordType}}{{Name}}</h2>
1717
<ul>
1818
{{#HasEnums}}
1919
<li class="sidebar-section">

clang-tools-extra/test/clang-doc/json/concept.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ concept Incrementable = requires(T x) {
3131
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
3232
// CHECK-NEXT: }
3333
// CHECK-NEXT: ],
34-
// CHECK: "Name": "",
34+
// CHECK: "Name": "Global Namespace",
3535
// CHECK: "USR": "0000000000000000000000000000000000000000"
3636
// CHECK: }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef int MyTypedef;
7575
// CHECK-NEXT: "HasEnums": true,
7676
// CHECK-NEXT: "HasRecords": true,
7777
// CHECK-NEXT: "InfoType": "namespace",
78-
// CHECK-NEXT: "Name": "",
78+
// CHECK-NEXT: "Name": "Global Namespace",
7979
// CHECK-NEXT: "Namespaces": [
8080
// CHECK-NEXT: {
8181
// CHECK-NEXT: "End": true,

clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace MyNamespace {
1919
// CHECK-GLOBAL: <main>
2020
// CHECK-GLOBAL-NEXT: <div class="container">
2121
// CHECK-GLOBAL-NEXT: <div class="sidebar">
22-
// CHECK-GLOBAL-NEXT: <h2> </h2>
22+
// CHECK-GLOBAL-NEXT: <h2>Global Namespace</h2>
2323
// CHECK-GLOBAL-NEXT: <ul>
2424
// CHECK-GLOBAL-NEXT: </ul>
2525
// CHECK-GLOBAL-NEXT: </div>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AnonClass {};
6363
// MD-ANON-INDEX: ### anonFunction
6464
// MD-ANON-INDEX: *void anonFunction()*
6565

66-
// HTML-ANON-INDEX: <h2> @nonymous_namespace</h2>
66+
// HTML-ANON-INDEX: <h2>@nonymous_namespace</h2>
6767
// HTML-ANON-INDEX: <h2>Inner Classes</h2>
6868
// HTML-ANON-INDEX: <ul class="class-container">
6969
// HTML-ANON-INDEX: <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
@@ -119,7 +119,7 @@ class ClassInNestedNamespace {};
119119
// MD-NESTED-INDEX: *void functionInNestedNamespace()*
120120
// MD-NESTED-INDEX: Function in NestedNamespace
121121

122-
// HTML-NESTED-INDEX: <h2> NestedNamespace</h2>
122+
// HTML-NESTED-INDEX: <h2>NestedNamespace</h2>
123123
// HTML-NESTED-INDEX: <h2>Inner Classes</h2>
124124
// HTML-NESTED-INDEX: <ul class="class-container">
125125
// HTML-NESTED-INDEX: <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
@@ -145,7 +145,7 @@ class ClassInNestedNamespace {};
145145
// MD-PRIMARY-INDEX: *void functionInPrimaryNamespace()*
146146
// MD-PRIMARY-INDEX: Function in PrimaryNamespace
147147

148-
// HTML-PRIMARY-INDEX: <h2> PrimaryNamespace</h2>
148+
// HTML-PRIMARY-INDEX: <h2>PrimaryNamespace</h2>
149149
// HTML-PRIMARY-INDEX-NOT: <h2 id="Namespaces">Namespaces</h2>
150150
// HTML-PRIMARY-INDEX-NOT: <a href="NestedNamespace{{[\/]}}index.html">NestedNamespace</a>
151151
// HTML-PRIMARY-INDEX <h2>Inner Classes</h2>
@@ -189,7 +189,7 @@ class ClassInAnotherNamespace {};
189189
// MD-ANOTHER-INDEX: *void functionInAnotherNamespace()*
190190
// MD-ANOTHER-INDEX: Function in AnotherNamespace
191191

192-
// HTML-ANOTHER-INDEX: <h2> AnotherNamespace</h2>
192+
// HTML-ANOTHER-INDEX: <h2>AnotherNamespace</h2>
193193
// HTML-ANOTHER-INDEX: <h2>Inner Classes</h2>
194194
// HTML-ANOTHER-INDEX: <ul class="class-container">
195195
// HTML-ANOTHER-INDEX: <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">

clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ TEST_F(JSONGeneratorTest, emitNamespaceJSON) {
245245
"HasEnums": true,
246246
"HasRecords": true,
247247
"InfoType": "namespace",
248-
"Name": "Namespace",
248+
"Name": "Global Namespace",
249249
"Namespace": [
250250
"A"
251251
],

0 commit comments

Comments
 (0)