If a DeclContext's lookups need to be reconciled, and we're given external declarations for a name, reconcile first. Otherwise, when we come to reconcile, we'll ask for external declarations for that name again. No functionality change intended.

llvm-svn: 204692
This commit is contained in:
Richard Smith 2014-03-25 00:34:21 +00:00
parent 05332ab354
commit a8b7459115
2 changed files with 16 additions and 8 deletions

View File

@ -1655,7 +1655,7 @@ public:
void dumpLookups(llvm::raw_ostream &OS) const; void dumpLookups(llvm::raw_ostream &OS) const;
private: private:
void reconcileExternalVisibleStorage(); void reconcileExternalVisibleStorage() const;
void LoadLexicalDeclsFromExternalStorage() const; void LoadLexicalDeclsFromExternalStorage() const;
/// @brief Makes a declaration visible within this context, but /// @brief Makes a declaration visible within this context, but

View File

@ -965,13 +965,12 @@ DeclContext::BuildDeclChain(ArrayRef<Decl*> Decls,
/// \brief We have just acquired external visible storage, and we already have /// \brief We have just acquired external visible storage, and we already have
/// built a lookup map. For every name in the map, pull in the new names from /// built a lookup map. For every name in the map, pull in the new names from
/// the external storage. /// the external storage.
void DeclContext::reconcileExternalVisibleStorage() { void DeclContext::reconcileExternalVisibleStorage() const {
assert(NeedToReconcileExternalVisibleStorage && LookupPtr.getPointer()); assert(NeedToReconcileExternalVisibleStorage && LookupPtr.getPointer());
NeedToReconcileExternalVisibleStorage = false; NeedToReconcileExternalVisibleStorage = false;
StoredDeclsMap &Map = *LookupPtr.getPointer(); for (auto &Lookup : *LookupPtr.getPointer())
for (StoredDeclsMap::iterator I = Map.begin(); I != Map.end(); ++I) Lookup.second.setHasExternalDecls();
I->second.setHasExternalDecls();
} }
/// \brief Load the declarations within this lexical storage from an /// \brief Load the declarations within this lexical storage from an
@ -1023,6 +1022,8 @@ ExternalASTSource::SetNoExternalVisibleDeclsForName(const DeclContext *DC,
StoredDeclsMap *Map; StoredDeclsMap *Map;
if (!(Map = DC->LookupPtr.getPointer())) if (!(Map = DC->LookupPtr.getPointer()))
Map = DC->CreateStoredDeclsMap(Context); Map = DC->CreateStoredDeclsMap(Context);
if (DC->NeedToReconcileExternalVisibleStorage)
DC->reconcileExternalVisibleStorage();
(*Map)[Name].removeExternalDecls(); (*Map)[Name].removeExternalDecls();
@ -1037,6 +1038,8 @@ ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC,
StoredDeclsMap *Map; StoredDeclsMap *Map;
if (!(Map = DC->LookupPtr.getPointer())) if (!(Map = DC->LookupPtr.getPointer()))
Map = DC->CreateStoredDeclsMap(Context); Map = DC->CreateStoredDeclsMap(Context);
if (DC->NeedToReconcileExternalVisibleStorage)
DC->reconcileExternalVisibleStorage();
StoredDeclsList &List = (*Map)[Name]; StoredDeclsList &List = (*Map)[Name];
@ -1208,6 +1211,10 @@ static bool shouldBeHidden(NamedDecl *D) {
/// buildLookup - Build the lookup data structure with all of the /// buildLookup - Build the lookup data structure with all of the
/// declarations in this DeclContext (and any other contexts linked /// declarations in this DeclContext (and any other contexts linked
/// to it or transparent contexts nested within it) and return it. /// to it or transparent contexts nested within it) and return it.
///
/// Note that the produced map may miss out declarations from an
/// external source. If it does, those entries will be marked with
/// the 'hasExternalDecls' flag.
StoredDeclsMap *DeclContext::buildLookup() { StoredDeclsMap *DeclContext::buildLookup() {
assert(this == getPrimaryContext() && "buildLookup called on non-primary DC"); assert(this == getPrimaryContext() && "buildLookup called on non-primary DC");
@ -1223,7 +1230,6 @@ StoredDeclsMap *DeclContext::buildLookup() {
// We no longer have any lazy decls. // We no longer have any lazy decls.
LookupPtr.setInt(false); LookupPtr.setInt(false);
NeedToReconcileExternalVisibleStorage = false;
return LookupPtr.getPointer(); return LookupPtr.getPointer();
} }
@ -1272,11 +1278,13 @@ DeclContext::lookup(DeclarationName Name) {
return PrimaryContext->lookup(Name); return PrimaryContext->lookup(Name);
if (hasExternalVisibleStorage()) { if (hasExternalVisibleStorage()) {
if (NeedToReconcileExternalVisibleStorage)
reconcileExternalVisibleStorage();
StoredDeclsMap *Map = LookupPtr.getPointer(); StoredDeclsMap *Map = LookupPtr.getPointer();
if (LookupPtr.getInt()) if (LookupPtr.getInt())
Map = buildLookup(); Map = buildLookup();
else if (NeedToReconcileExternalVisibleStorage)
reconcileExternalVisibleStorage();
if (!Map) if (!Map)
Map = CreateStoredDeclsMap(getParentASTContext()); Map = CreateStoredDeclsMap(getParentASTContext());