The StoredDeclsList is reworked and more user-friendly.
See llvm/llvm-project@0cb7e7ca0c
This commit is contained in:
parent
1320eb67c6
commit
6fb14e3f8a
@ -175,8 +175,7 @@ static Decl* handleRedelaration(Decl* D, DeclContext* DC) {
|
||||
};
|
||||
if (!hasDecl(decls, MostRecentNotThis) && hasDecl(decls, ND)) {
|
||||
// The decl was registered in the lookup, update it.
|
||||
Pos->second.HandleRedeclaration(MostRecentNotThis,
|
||||
/*IsKnownNewer*/ true);
|
||||
Pos->second.addOrReplaceDecl(MostRecentNotThis);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -411,49 +410,19 @@ bool DeclUnloader::VisitRedeclarable(clang::Redeclarable<T>* R, DeclContext* DC)
|
||||
// Make sure we the decl doesn't exist in the lookup tables.
|
||||
StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
|
||||
if (Pos != Map->end()) {
|
||||
// Most decls only have one entry in their list, special case it.
|
||||
if (Pos->second.getAsDecl() == ND) {
|
||||
// This is the only decl, no need to call Pos->second.remove(ND);
|
||||
// as it only sets data to nullptr, just remove the entire entry
|
||||
StoredDeclsList &List = Pos->second;
|
||||
// In some cases clang puts an entry in the list without a decl pointer.
|
||||
// Clean it up.
|
||||
if (List.isNull()) {
|
||||
Map->erase(Pos);
|
||||
return;
|
||||
}
|
||||
else if (StoredDeclsList::DeclsTy* Vec = Pos->second.getAsVector()) {
|
||||
// Otherwise iterate over the list with entries with the same name.
|
||||
for (NamedDecl* NDi : *Vec) {
|
||||
if (NDi == ND)
|
||||
Pos->second.remove(ND);
|
||||
}
|
||||
if (Vec->empty())
|
||||
Map->erase(Pos);
|
||||
}
|
||||
else if (Pos->second.isNull()) // least common case
|
||||
List.remove(ND);
|
||||
if (List.isNull())
|
||||
Map->erase(Pos);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Make sure we the decl doesn't exist in the lookup tables.
|
||||
static void checkDeclIsGone(StoredDeclsMap* Map, NamedDecl* ND) {
|
||||
assert(Map && ND && "checkDeclIsGone recieved NULL value(s)");
|
||||
StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
|
||||
if ( Pos != Map->end()) {
|
||||
// Most decls only have one entry in their list, special case it.
|
||||
if (NamedDecl* OldD = Pos->second.getAsDecl())
|
||||
assert(OldD != ND && "Lookup entry still exists.");
|
||||
else if (StoredDeclsList::DeclsTy* Vec = Pos->second.getAsVector()) {
|
||||
// Otherwise iterate over the list with entries with the same name.
|
||||
// TODO: Walk the redeclaration chain if the entry was a redeclaration.
|
||||
|
||||
for (StoredDeclsList::DeclsTy::const_iterator I = Vec->begin(),
|
||||
E = Vec->end(); I != E; ++I)
|
||||
assert(*I != ND && "Lookup entry still exists.");
|
||||
}
|
||||
else
|
||||
assert(Pos->second.isNull() && "!?");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool DeclUnloader::VisitNamedDecl(NamedDecl* ND) {
|
||||
bool Successful = VisitDecl(ND);
|
||||
|
||||
@ -476,12 +445,9 @@ bool DeclUnloader::VisitRedeclarable(clang::Redeclarable<T>* R, DeclContext* DC)
|
||||
|
||||
// Cleanup the lookup tables.
|
||||
// DeclContexts like EnumDecls don't have lookup maps.
|
||||
if (StoredDeclsMap* Map = DC->getPrimaryContext()->getLookupPtr()) {
|
||||
// FIXME: Remove once we upstream this patch: D119675
|
||||
if (StoredDeclsMap* Map = DC->getPrimaryContext()->getLookupPtr())
|
||||
eraseDeclFromMap(Map, ND);
|
||||
#ifndef NDEBUG
|
||||
checkDeclIsGone(Map, ND);
|
||||
#endif
|
||||
}
|
||||
|
||||
return Successful;
|
||||
}
|
||||
@ -506,7 +472,7 @@ bool DeclUnloader::VisitRedeclarable(clang::Redeclarable<T>* R, DeclContext* DC)
|
||||
Successful &= VisitNamedDecl(USD);
|
||||
|
||||
// Unregister from the using decl that it shadows.
|
||||
USD->getUsingDecl()->removeShadowDecl(USD);
|
||||
USD->getIntroducer()->removeShadowDecl(USD);
|
||||
|
||||
return Successful;
|
||||
}
|
||||
|
@ -82,15 +82,14 @@ namespace cling {
|
||||
if (utils::Analyze::isOnScopeChains(D, *m_Sema))
|
||||
m_Sema->IdResolver.RemoveDecl(D);
|
||||
}
|
||||
clang::StoredDeclsList &SDL = (*m_TU->getLookupPtr())[D->getDeclName()];
|
||||
if (SDL.getAsDecl() == D) {
|
||||
SDL.setOnlyValue(nullptr);
|
||||
}
|
||||
if (auto Vec = SDL.getAsVector()) {
|
||||
// FIXME: investigate why StoredDeclList has duplicated entries coming from PCM.
|
||||
Vec->erase(std::remove_if(Vec->begin(), Vec->end(),
|
||||
[D](Decl *Other) { return cast<Decl>(D) == Other; }),
|
||||
Vec->end());
|
||||
if (StoredDeclsMap* Map = m_TU->getLookupPtr()) {
|
||||
StoredDeclsMap::iterator Pos = Map->find(D->getDeclName());
|
||||
if (Pos != Map->end() && !Pos->second.isNull()) {
|
||||
StoredDeclsList &List = Pos->second;
|
||||
List.remove(D);
|
||||
if (List.isNull())
|
||||
Map->erase(Pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (InterpreterCallbacks *IC = m_Interp.getCallbacks())
|
||||
|
Loading…
Reference in New Issue
Block a user