Get the fully qualified template name of the template using libtooling

I am trying to use a template class justification libtoolingfor printing CXXRecordDeclwith a template template parameter. Unfortunately, the string representation of the template template parameter is not complete (for example, it skips namespaces).

I am printing CXXRecordDeclusing this code:

clang::PrintingPolicy policy = compiler_instance->getLangOpts();
std::string name = decl->getTypeForDecl()->getCanonicalTypeInternal().getAsString(policy);

Here is an example where I expect the output to be ns::A<ns::B>, but I get ns::A<B>:

namespace ns {

template <template <class> class T>
class A {
  T<int> x;
};

template <class T>
class B {
  T y;
};

} // namespace ns

int main(int argc, char **argv)
{
  using namespace ns;
  A<B> z;
}

How to print a fully qualified class name with a template template parameter?

In the corresponding note, is there a way to do this without a call getCanonicalTypeInternalthat sounds like an internal function?

[ # 1] decl->getQualifiedNameAsString(), ns::A.

[ # 2] Cling . . ( ). , ns::A<void (B)> ns::A<void (ns::B)>:

namespace ns {

class B { };

template <class T>
class A { };

} // namespace

int main(int argc, char **argv)
{
  using namespace ns;

  A<void (B)> x;
}

[ # 3] . : CERN. . .

+4
1

: decl->getQualifiedNameAsString();

, clang/libclang , , ,

. http://lists.llvm.org/pipermail/cfe-dev/2015-October/045473.html

cling clang, ​​, . :

https://root.cern.ch/gitweb?p=root.git;a=blob;f=interpreter/cling/include/cling/Utils/AST.h;h=91cea2ef82f6a6b2ed4671d43253b1c0ebd86fd4;hb=HEAD

std::string GetFullyQualifiedName(clang::QualType QT,
                                        const clang::ASTContext &Ctx);

- , , ns::A<ns::B>

, clang/libclang, , .

+2

Source: https://habr.com/ru/post/1615344/


All Articles