llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (Sandeep2265) <details> <summary>Changes</summary> Added function checks if a type is a TypedefType and, if so, returns its original typedef name instead of printing the full type.This helps keep typedef names preserved in ExtractAPI declaration fragments instead of showing the underlying struct type. --- Full diff: https://github.com/llvm/llvm-project/pull/167319.diff 1 Files Affected: - (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (+13-1) ``````````diff diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp index e5eda46df8056..16a524702e963 100644 --- a/clang/lib/ExtractAPI/DeclarationFragments.cpp +++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp @@ -63,6 +63,17 @@ void findTypeLocForBlockDecl(const clang::TypeSourceInfo *TSInfo, } // namespace +static std::string OriginalNameTypedef(const clang::QualType &qt, + const clang::PrintingPolicy &policy) { + if (const auto *tt = llvm::dyn_cast<clang::TypedefType>(qt.getTypePtrOrNull())) { + const auto *td = tt->getDecl(); + if (!td->getName().empty()) + return td->getName().str(); + } + return qt.getAsString(policy); +} + + DeclarationFragments & DeclarationFragments::appendUnduplicatedTextCharacter(char Character) { if (!Fragments.empty()) { @@ -452,7 +463,8 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType( // Default fragment builder for other kinds of types (BuiltinType etc.) SmallString<128> USR; clang::index::generateUSRForType(Base, Context, USR); - Fragments.append(Base.getAsString(), + std::string typestr = OriginalNameTypedef(Base, Context.getPrintingPolicy()); + Fragments.append(typestr, DeclarationFragments::FragmentKind::TypeIdentifier, USR); return Fragments; `````````` </details> https://github.com/llvm/llvm-project/pull/167319 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
