[cfe-dev] Get the specialized class name and function name
David Blaikie via cfe-dev
cfe-dev at lists.llvm.org
Sat Feb 29 14:47:36 PST 2020
I don't know the specific way off-hand, but my usual approach to finding
such APIs would be to run clang on a source file that produces a
warning/error/diagnostic with the name you want - then running that under a
debugger to see how it is getting that name
On Wed, Feb 26, 2020 at 11:05 PM zxhuan via cfe-dev <cfe-dev at lists.llvm.org>
wrote:
> Hey guys,
>
> I am new to clang and I am trying to get the specialized name of template
> classes and functions. For example, the std::map container is an STL class
> with template parameters. map<string, int> should be expanded as something
> similar to std::map<std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char> >, int>. I have written a
> simple clang tool to get the function name and the class name of functions,
> here is a piece of code:
>
> map<string, set<string>> func_set;
>
> DeclarationMatcher methodMatcher = cxxMethodDecl().bind("methods");
>
> class MethodPrinter : public MatchFinder::MatchCallback {
> public :
> virtual void run(const MatchFinder::MatchResult &Result) {
> if (const CXXMethodDecl *md =
> Result.Nodes.getNodeAs<clang::CXXMethodDecl>("methods")) {
> string f_name = md->getNameAsString();
> string c_name = md->getParent()->getNameAsString();
>
> if (auto tsd =
> dyn_cast<ClassTemplateSpecializationDecl>(md->getParent()))
> c_name = tsd->getNameAsString();
>
> func_set[c_name].insert(f_name);
> }
> }
> };
>
> This piece of code is getting me started, but not quite there. The
> getNameAsString() method just gives a very simple name, without the
> template parameters specialized. I am wondering if there is a way to do
> that.
>
> Any help is appreciated!
>
> Jason
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200229/e2beae36/attachment.html>
More information about the cfe-dev
mailing list