17#include "llvm/Support/FormatVariadic.h"
23struct Builder : RecursiveASTVisitor<Builder> {
24 ASTImporterLookupTable &
LT;
25 Builder(ASTImporterLookupTable <) :
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)) {
70 }
else if (isa<UsingType>(Ty)) {
73 llvm_unreachable(
"Unhandled type of friend class");
81 bool shouldVisitTemplateInstantiations()
const {
return true; }
82 bool shouldVisitImplicitCode()
const {
return true; }
98 if (
auto *Ns = dyn_cast<NamespaceDecl>(
D->getDeclContext()))
100 add(
D->getDeclContext(),
D);
105 DeclList &Decls = LookupTable[DC][ND->
getDeclName()];
110void ASTImporterLookupTable::remove(DeclContext *DC, NamedDecl *ND) {
111 const DeclarationName Name = ND->getDeclName();
112 DeclList &Decls = LookupTable[DC][Name];
113 bool EraseResult = Decls.remove(ND);
117 std::string Message =
118 llvm::formatv(
"Trying to remove not contained Decl '{0}' of type {1}",
119 Name.getAsString(), DC->getDeclKindName())
121 llvm_unreachable(Message.c_str());
146 "DeclContext should be changed before update");
149 "Decl should not be found in the old context if already in the new");
165 if (DCI == LookupTable.end())
168 const auto &FoundNameMap = DCI->second;
169 auto NamesI = FoundNameMap.find(Name);
170 if (NamesI == FoundNameMap.end())
173 return NamesI->second;
182 if (DCI == LookupTable.end())
183 llvm::errs() <<
"empty\n";
184 const auto &FoundNameMap = DCI->second;
185 for (
const auto &Entry : FoundNameMap) {
187 llvm::errs() <<
"==== Name: ";
189 const DeclList& List = Entry.second;
197 for (
const auto &Entry : LookupTable) {
200 llvm::errs() <<
"== DC:" << cast<Decl>(DC) << Primary <<
"\n";
ASTImporterLookupTable & LT
Decl * getVaListTagDecl() const
Retrieve the C type declaration corresponding to the predefined __va_list_tag type used to help defin...
void update(NamedDecl *ND, DeclContext *OldDC)
LookupResult lookup(DeclContext *DC, DeclarationName Name) const
void updateForced(NamedDecl *ND, DeclContext *OldDC)
ASTImporterLookupTable(TranslationUnitDecl &TU)
bool contains(DeclContext *DC, NamedDecl *ND) const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
DeclContext * getDeclContext()
The name of a declaration.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
The top declaration context.
ASTContext & getASTContext() const
The JSON file list parser is used to communicate input to InstallAPI.