17 #include "llvm/Support/FormatVariadic.h"
23 struct Builder : RecursiveASTVisitor<Builder> {
24 ASTImporterLookupTable &
LT;
25 Builder(ASTImporterLookupTable &
LT) :
LT(
LT) {}
27 bool VisitTypedefNameDecl(TypedefNameDecl *D) {
28 QualType Ty = D->getUnderlyingType();
29 Ty = Ty.getCanonicalType();
30 if (
const auto *RTy = dyn_cast<RecordType>(Ty)) {
31 LT.add(RTy->getAsRecordDecl());
33 for (
auto *it : RTy->getAsRecordDecl()->fields()) {
40 bool VisitNamedDecl(NamedDecl *D) {
49 bool VisitFriendDecl(FriendDecl *D) {
50 if (D->getFriendType()) {
51 QualType Ty = D->getFriendType()->getType();
52 if (isa<ElaboratedType>(Ty))
53 Ty = cast<ElaboratedType>(Ty)->getNamedType();
58 if (!Ty->isDependentType()) {
59 if (
const auto *RTy = dyn_cast<RecordType>(Ty))
60 LT.add(RTy->getAsCXXRecordDecl());
61 else if (
const auto *SpecTy = dyn_cast<TemplateSpecializationType>(Ty))
62 LT.add(SpecTy->getAsCXXRecordDecl());
63 else if (
const auto *SubstTy =
64 dyn_cast<SubstTemplateTypeParmType>(Ty)) {
65 if (SubstTy->getAsCXXRecordDecl())
66 LT.add(SubstTy->getAsCXXRecordDecl());
67 }
else if (isa<TypedefType>(Ty)) {
71 llvm_unreachable(
"Unhandled type of friend class");
79 bool shouldVisitTemplateInstantiations()
const {
return true; }
80 bool shouldVisitImplicitCode()
const {
return true; }
91 DeclList &Decls = LookupTable[DC][ND->
getDeclName()];
96 void ASTImporterLookupTable::remove(DeclContext *DC, NamedDecl *ND) {
97 const DeclarationName Name = ND->getDeclName();
98 DeclList &Decls = LookupTable[DC][Name];
99 bool EraseResult = Decls.remove(ND);
104 llvm::formatv(
"Trying to remove not contained Decl '{0}' of type {1}",
105 Name.getAsString(), DC->getDeclKindName())
107 llvm_unreachable(Message.c_str());
132 "DeclContext should be changed before update");
135 "Decl should not be found in the old context if already in the new");
151 if (DCI == LookupTable.end())
154 const auto &FoundNameMap = DCI->second;
155 auto NamesI = FoundNameMap.find(Name);
156 if (NamesI == FoundNameMap.end())
159 return NamesI->second;
168 if (DCI == LookupTable.end())
169 llvm::errs() <<
"empty\n";
170 const auto &FoundNameMap = DCI->second;
171 for (
const auto &Entry : FoundNameMap) {
173 llvm::errs() <<
"==== Name: ";
175 const DeclList& List = Entry.second;
183 for (
const auto &Entry : LookupTable) {
186 llvm::errs() <<
"== DC:" << cast<Decl>(DC) << Primary <<
"\n";