-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-doc] create namespace names according to their paths #162886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) ChangesNamespace filenames didn't consider their paths, so foo::tools would use Full diff: https://github.com/llvm/llvm-project/pull/162886.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 1b08b1791b6eb..df816d78d77fe 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -584,7 +584,13 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
FileName = RecordSymbolInfo->MangledName;
} else if (I->USR == GlobalNamespace)
FileName = "index";
- else
+ else if (I->IT == InfoType::IT_namespace) {
+ for (const auto &NS : I->Namespace) {
+ FileName += NS.Name;
+ FileName += "_";
+ }
+ FileName += I->Name;
+ } else
FileName = I->Name;
sys::path::append(Path, FileName + ".json");
return FileName;
diff --git a/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
new file mode 100644
index 0000000000000..04fcfc1dc0a85
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: FileCheck %s < %t/json/foo_tools.json --check-prefix=CHECK-FOO
+// RUN: FileCheck %s < %t/json/bar_tools.json --check-prefix=CHECK-BAR
+
+namespace foo {
+ namespace tools {
+ class FooTools {};
+ } // namespace tools
+} // namespace foo
+
+namespace bar {
+ namespace tools {
+ class BarTools {};
+ } // namespace tools
+} // namespace bar
+
+// CHECK-FOO: "Name": "tools"
+
+// CHECK-BAR: "Name": "tools"
diff --git a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
index b19afc1885104..cf19e1e34a818 100644
--- a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED
-// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER
+// RUN: FileCheck %s < %t/json/nested_inner.json --check-prefix=INNER
namespace nested {
int Global;
|
else if (I->IT == InfoType::IT_namespace) { | ||
for (const auto &NS : I->Namespace) { | ||
FileName += NS.Name; | ||
FileName += "_"; | ||
} | ||
FileName += I->Name; | ||
} else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we'd be better off just moving away from the the flat dir structure. the number of files/items in a namespace can be quite large, and its probably a better choice to keep the number of files in a directory relatively small. Things like the global namespace may need more thought, since I think they may have lots of things in it. for example C projects will all just have everything in the global namespace, right? so we may also want to consider mirroring the source file directory structure. but moving away from the flat structure first and then using a different schema if we decide its worth the effort seems like a good path.
For now though, I'd like to get these bugs fixed, so lets just add a TODO about that, and go w/ what you have here. I think its more important to have a working thing, than stay in limbo while we figure out a path forward.
b345c72
to
17048c0
Compare
420db87
to
8167825
Compare
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.
8167825
to
24085f6
Compare
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.