diff options
author | Julie Hockett <juliehockett@google.com> | 2019-06-24 19:31:02 +0000 |
---|---|---|
committer | Julie Hockett <juliehockett@google.com> | 2019-06-24 19:31:02 +0000 |
commit | b1f01e27ec0cea2f28eaa2026aa1e63a3b2ae0f0 (patch) | |
tree | c35282329e294ecf439e4908611a8a61345ac6e9 /clang-tools-extra/clang-doc/Serialize.cpp | |
parent | ea08248b2bc9ab6cd14cfd1a05c4fb0fae49e97a (diff) | |
download | bcm5719-llvm-b1f01e27ec0cea2f28eaa2026aa1e63a3b2ae0f0.tar.gz bcm5719-llvm-b1f01e27ec0cea2f28eaa2026aa1e63a3b2ae0f0.zip |
[clang-doc] Add basic support for templates and typedef
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
Diffstat (limited to 'clang-tools-extra/clang-doc/Serialize.cpp')
-rw-r--r-- | clang-tools-extra/clang-doc/Serialize.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
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<RecordType>(); - 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<TemplateSpecializationType>()) { + 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<Info> 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<CXXRecordDecl>(D)) + if (const auto *C = dyn_cast<CXXRecordDecl>(D)) { + if (const TypedefNameDecl *TD = C->getTypedefNameForAnonDecl()) { + I->Name = TD->getNameAsString(); + I->IsTypeDef = true; + } parseBases(*I, C); + } return std::unique_ptr<Info>{std::move(I)}; } @@ -376,9 +384,16 @@ std::unique_ptr<Info> 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<ClassTemplateSpecializationDecl>(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 |