-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-doc] mangle template specialization file names #144617
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
#include "BitcodeWriter.h" | ||
#include "clang/AST/Attr.h" | ||
#include "clang/AST/Comment.h" | ||
#include "clang/AST/Mangle.h" | ||
#include "clang/Index/USRGeneration.h" | ||
#include "clang/Lex/Lexer.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
|
@@ -909,6 +910,13 @@ emitInfo(const RecordDecl *D, const FullComment *FC, Location Loc, | |
RI->Template.emplace(); | ||
RI->Template->Specialization.emplace(); | ||
auto &Specialization = *RI->Template->Specialization; | ||
auto *Mangler = ItaniumMangleContext::create( | ||
D->getASTContext(), D->getASTContext().getDiagnostics()); | ||
std::string MangledName; | ||
llvm::raw_string_ostream Stream(MangledName); | ||
Mangler->mangleCXXVTT(dyn_cast<CXXRecordDecl>(D), Stream); | ||
Specialization.MangledName.emplace(MangledName); | ||
delete Mangler; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice to keep this mangler somewhere so that it's not allocated/deleted constantly. If it was kept in the Clang-Doc Context, it'd have to be passed specifically to this emitInfo which would break the pattern we have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it just be static to the function? |
||
|
||
// What this is a specialization of. | ||
auto SpecOf = CTSD->getSpecializedTemplateOrPartial(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// RUN: rm -rf %t && mkdir -p %t | ||
// RUN: clang-doc --output=%t --format=json --executor=standalone %s | ||
// RUN: FileCheck %s < %t/GlobalNamespace/_ZTT7MyClassIiE.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this serves the same purpose, but it'd be nice to have an explicit check for the correct file name. Maybe just a call to |
||
|
||
template<typename T> class MyClass; | ||
|
||
template<> class MyClass<int>; | ||
|
||
// CHECK: "Name": "MyClass", | ||
// CHECK: "Template": { | ||
// CHECK-NEXT: "Specialization": { | ||
// CHECK-NEXT: "Parameters": [ | ||
// CHECK-NEXT: "int" | ||
// CHECK-NEXT: ], | ||
// CHECK-NEXT: "SpecializationOf": "{{[0-9A-F]*}}" |
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.
can you just always use a mangled name for everything? for C mangling would just be the name, but for anything in C++, it'd get you a unique name. Seems reasonable to do unconditionally. WDYT?