void DeclContext::localUncachedLookup(DeclarationName Name, SmallVectorImpl<NamedDecl *> &Results) { Results.clear(); // If there's no external storage, just perform a normal lookup and copy // the results. if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) { lookup_result LookupResults = lookup(Name); Results.insert(Results.end(), LookupResults.begin(), LookupResults.end()); return; } // If we have a lookup table, check there first. Maybe we'll get lucky. if (Name && !LookupPtr.getInt()) { if (StoredDeclsMap *Map = LookupPtr.getPointer()) { StoredDeclsMap::iterator Pos = Map->find(Name); if (Pos != Map->end()) { Results.insert(Results.end(), Pos->second.getLookupResult().begin(), Pos->second.getLookupResult().end()); return; } } } // Slow case: grovel through the declarations in our chain looking for // matches. for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) { if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) if (ND->getDeclName() == Name) Results.push_back(ND); } }
void Decl::Destroy(ASTContext &C) { // Free attributes for this decl. if (HasAttrs) { C.getDeclAttrs(this)->Destroy(C); invalidateAttrs(); HasAttrs = false; } #if 0 // FIXME: Once ownership is fully understood, we can enable this code if (DeclContext *DC = dyn_cast<DeclContext>(this)) DC->decls_begin()->Destroy(C); // Observe the unrolled recursion. By setting N->NextDeclInContext = 0x0 // within the loop, only the Destroy method for the first Decl // will deallocate all of the Decls in a chain. Decl* N = getNextDeclInContext(); while (N) { Decl* Tmp = N->getNextDeclInContext(); N->NextDeclInContext = 0; N->Destroy(C); N = Tmp; } this->~Decl(); C.Deallocate((void *)this); #endif }
DeclContext::lookup_result DeclContext::lookup(DeclarationName Name) { assert(DeclKind != Decl::LinkageSpec && "Should not perform lookups into linkage specs!"); DeclContext *PrimaryContext = getPrimaryContext(); if (PrimaryContext != this) return PrimaryContext->lookup(Name); #if AXEL_LOOKUP_CHANGES StoredDeclsMap *Map = LookupPtr.getPointer(); if (LookupPtr.getInt()) Map = buildLookup(); #endif if (hasExternalVisibleStorage()) { // If a PCH has a result for this name, and we have a local declaration, we // will have imported the PCH result when adding the local declaration. // FIXME: For modules, we could have had more declarations added by module // imoprts since we saw the declaration of the local name. #if AXEL_LOOKUP_CHANGES if (Map) { #else if (StoredDeclsMap *Map = LookupPtr.getPointer()) { #endif StoredDeclsMap::iterator I = Map->find(Name); if (I != Map->end()) return I->second.getLookupResult(); } ExternalASTSource *Source = getParentASTContext().getExternalSource(); return Source->FindExternalVisibleDeclsByName(this, Name); } #ifndef AXEL_LOOKUP_CHANGES StoredDeclsMap *Map = LookupPtr.getPointer(); if (LookupPtr.getInt()) Map = buildLookup(); #endif if (!Map) return lookup_result(lookup_iterator(0), lookup_iterator(0)); StoredDeclsMap::iterator I = Map->find(Name); if (I == Map->end()) return lookup_result(lookup_iterator(0), lookup_iterator(0)); return I->second.getLookupResult(); } void DeclContext::localUncachedLookup(DeclarationName Name, llvm::SmallVectorImpl<NamedDecl *> &Results) { Results.clear(); // If there's no external storage, just perform a normal lookup and copy // the results. if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) { lookup_result LookupResults = lookup(Name); Results.insert(Results.end(), LookupResults.first, LookupResults.second); return; } // If we have a lookup table, check there first. Maybe we'll get lucky. if (Name) { if (StoredDeclsMap *Map = LookupPtr.getPointer()) { StoredDeclsMap::iterator Pos = Map->find(Name); if (Pos != Map->end()) { Results.insert(Results.end(), Pos->second.getLookupResult().first, Pos->second.getLookupResult().second); return; } } } // Slow case: grovel through the declarations in our chain looking for // matches. for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) { if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) if (ND->getDeclName() == Name) Results.push_back(ND); } }