diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -810,6 +810,8 @@ is a replacement for a template type parameter (previously reported a ``CXType_Unexposed``). - Introduced the new function ``clang_Type_getReplacementType`` which gets the type replacing the template type parameter when type kind is ``CXType_SubstTemplateTypeParm``. +- Introduced the new function ``clang_Type_getFullyQualifiedName``, which gets the fully + qualified name of the given type, including qualification of all template parameters. Static Analyzer --------------- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2846,6 +2846,13 @@ */ CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. +*/ +CINDEX_LINKAGE CXString clang_Type_getFullyQualifiedName(CXType CT); + /** * Retrieve the underlying type of a typedef declaration. * diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp --- a/clang/tools/libclang/CXType.cpp +++ b/clang/tools/libclang/CXType.cpp @@ -20,6 +20,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/Type.h" +#include "clang/AST/QualTypeNames.h" #include "clang/Basic/AddressSpaces.h" #include "clang/Frontend/ASTUnit.h" @@ -309,6 +310,22 @@ return cxstring::createDup(OS.str()); } +CXString clang_Type_getFullyQualifiedName(CXType CT) { + QualType T = GetQualType(CT); + if (T.isNull()) + return cxstring::createEmpty(); + + CXTranslationUnit TU = GetTU(CT); + SmallString<64> Str; + llvm::raw_svector_ostream OS(Str); + PrintingPolicy PP(cxtu::getASTUnit(TU)->getASTContext().getLangOpts()); + + std::string qname = clang::TypeName::getFullyQualifiedName( + T, cxtu::getASTUnit(TU)->getASTContext(), PP); + + return cxstring::createDup(qname); +} + CXType clang_getTypedefDeclUnderlyingType(CXCursor C) { using namespace cxcursor; CXTranslationUnit TU = cxcursor::getCursorTU(C); diff --git a/clang/tools/libclang/libclang.map b/clang/tools/libclang/libclang.map --- a/clang/tools/libclang/libclang.map +++ b/clang/tools/libclang/libclang.map @@ -413,6 +413,7 @@ clang_CXXMethod_isDeleted; clang_CXXMethod_isCopyAssignmentOperator; clang_CXXMethod_isMoveAssignmentOperator; + clang_Type_getFullyQualifiedName; }; # Example of how to add a new symbol version entry. If you do add a new symbol