anderslanglands created this revision. anderslanglands added a reviewer: aaron.ballman. Herald added a subscriber: arphaman. Herald added a project: All. anderslanglands requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Not sure how to test this - adding it to c-index-test's PrintType will change *everything*, which doesn't seem like a great idea. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138377 Files: clang/docs/ReleaseNotes.rst clang/include/clang-c/Index.h clang/tools/libclang/CXType.cpp clang/tools/libclang/libclang.map Index: clang/tools/libclang/libclang.map =================================================================== --- clang/tools/libclang/libclang.map +++ 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 Index: clang/tools/libclang/CXType.cpp =================================================================== --- clang/tools/libclang/CXType.cpp +++ 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); Index: clang/include/clang-c/Index.h =================================================================== --- clang/include/clang-c/Index.h +++ 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. * Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ 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 ---------------
Index: clang/tools/libclang/libclang.map =================================================================== --- clang/tools/libclang/libclang.map +++ 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 Index: clang/tools/libclang/CXType.cpp =================================================================== --- clang/tools/libclang/CXType.cpp +++ 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); Index: clang/include/clang-c/Index.h =================================================================== --- clang/include/clang-c/Index.h +++ 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. * Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ 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 ---------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits