From b1f01e27ec0cea2f28eaa2026aa1e63a3b2ae0f0 Mon Sep 17 00:00:00 2001 From: Julie Hockett Date: Mon, 24 Jun 2019 19:31:02 +0000 Subject: [clang-doc] Add basic support for templates and typedef MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In serialize::parseBases(...), when a base record is a template specialization, the specialization was used as the parent. It should be the base template so there is only one file generated for this record. When the specialized template is implicitly declared the reference USR corresponded to the GlobalNamespace's USR, this will now be the base template's USR. More information about templates will be added later. In serialize::emiInfo(RecorDecl*, ...), typedef records were not handled and the name was empty. This is now handled and a IsTypeDef attribute is added to RecordInfo struct. In serialize::emitInfo(CXXMethodDecl*, ...), template specialization is handled like in serialize::parseBases(...). Bitcode writer and reader are modified to handle the new attribute of RecordInfo. Submitted on behalf of Diego Astiazarán (diegoaat97@gmail.com) Differential Revision: https://reviews.llvm.org/D63367 llvm-svn: 364222 --- clang-tools-extra/clang-doc/Serialize.cpp | 33 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'clang-tools-extra/clang-doc/Serialize.cpp') diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 2bd54cf2d98..11845e1a616 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -179,10 +179,9 @@ static SymbolID getUSRForDecl(const Decl *D) { } static RecordDecl *getDeclForType(const QualType &T) { - auto *Ty = T->getAs(); - if (!Ty) - return nullptr; - return Ty->getDecl()->getDefinition(); + if (const RecordDecl *D = T->getAsRecordDecl()) + return D->getDefinition(); + return nullptr; } static bool isPublic(const clang::AccessSpecifier AS, @@ -249,7 +248,11 @@ static void parseBases(RecordInfo &I, const CXXRecordDecl *D) { for (const CXXBaseSpecifier &B : D->bases()) { if (B.isVirtual()) continue; - if (const auto *P = getDeclForType(B.getType())) + if (const auto *Ty = B.getType()->getAs()) { + const TemplateDecl *D = Ty->getTemplateName().getAsTemplateDecl(); + I.Parents.emplace_back(getUSRForDecl(D), B.getType().getAsString(), + InfoType::IT_record); + } else if (const RecordDecl *P = getDeclForType(B.getType())) I.Parents.emplace_back(getUSRForDecl(P), P->getNameAsString(), InfoType::IT_record); else @@ -343,8 +346,13 @@ std::unique_ptr emitInfo(const RecordDecl *D, const FullComment *FC, populateSymbolInfo(*I, D, FC, LineNumber, File); I->TagType = D->getTagKind(); parseFields(*I, D, PublicOnly); - if (const auto *C = dyn_cast(D)) + if (const auto *C = dyn_cast(D)) { + if (const TypedefNameDecl *TD = C->getTypedefNameForAnonDecl()) { + I->Name = TD->getNameAsString(); + I->IsTypeDef = true; + } parseBases(*I, C); + } return std::unique_ptr{std::move(I)}; } @@ -376,9 +384,16 @@ std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC, populateFunctionInfo(Func, D, FC, LineNumber, File); Func.IsMethod = true; - SymbolID ParentUSR = getUSRForDecl(D->getParent()); - Func.Parent = Reference{ParentUSR, D->getParent()->getNameAsString(), - InfoType::IT_record}; + const NamedDecl *Parent = nullptr; + if (const auto *SD = + dyn_cast(D->getParent())) + Parent = SD->getSpecializedTemplate(); + else + Parent = D->getParent(); + + SymbolID ParentUSR = getUSRForDecl(Parent); + Func.Parent = + Reference{ParentUSR, Parent->getNameAsString(), InfoType::IT_record}; Func.Access = D->getAccess(); // Wrap in enclosing scope -- cgit v1.2.3