summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-01-07 09:11:48 +0000
committerDouglas Gregor <dgregor@apple.com>2012-01-07 09:11:48 +0000
commite57e752b71f0254e697156ed8c5c15040f53e6d6 (patch)
treea6b6d287391aff05c487f0cb9043cbb91353c5e7 /clang/lib/AST/DeclBase.cpp
parent43a1bd6ac7caf826c024eb05507b3c8fe8956dc3 (diff)
downloadbcm5719-llvm-e57e752b71f0254e697156ed8c5c15040f53e6d6.tar.gz
bcm5719-llvm-e57e752b71f0254e697156ed8c5c15040f53e6d6.zip
Switch NamespaceDecl from its own hand-rolled redeclaration chain over
to Redeclarable<NamespaceDecl>, so that we benefit from the improveed redeclaration deserialization and merging logic provided by Redeclarable<T>. Otherwise, no functionality change. As a drive-by fix, collapse the "inline" bit into the low bit of the original namespace/anonymous namespace, saving 8 bytes per NamespaceDecl on x86_64. llvm-svn: 147729
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r--clang/lib/AST/DeclBase.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 3fc507ebdb9..0312cfbc4ab 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -839,15 +839,21 @@ DeclContext *DeclContext::getPrimaryContext() {
}
}
-DeclContext *DeclContext::getNextContext() {
- switch (DeclKind) {
- case Decl::Namespace:
- // Return the next namespace
- return static_cast<NamespaceDecl*>(this)->getNextNamespace();
-
- default:
- return 0;
+void
+DeclContext::collectAllContexts(llvm::SmallVectorImpl<DeclContext *> &Contexts){
+ Contexts.clear();
+
+ if (DeclKind != Decl::Namespace) {
+ Contexts.push_back(this);
+ return;
}
+
+ NamespaceDecl *Self = static_cast<NamespaceDecl *>(this);
+ for (NamespaceDecl *N = Self->getMostRecentDeclaration(); N;
+ N = N->getPreviousDeclaration())
+ Contexts.push_back(N);
+
+ std::reverse(Contexts.begin(), Contexts.end());
}
std::pair<Decl *, Decl *>
@@ -1067,15 +1073,17 @@ void DeclContext::addDeclInternal(Decl *D) {
/// declarations in DCtx (and any other contexts linked to it or
/// transparent contexts nested within it).
void DeclContext::buildLookup(DeclContext *DCtx) {
- for (; DCtx; DCtx = DCtx->getNextContext()) {
- for (decl_iterator D = DCtx->decls_begin(),
- DEnd = DCtx->decls_end();
+ llvm::SmallVector<DeclContext *, 2> Contexts;
+ DCtx->collectAllContexts(Contexts);
+ for (unsigned I = 0, N = Contexts.size(); I != N; ++I) {
+ for (decl_iterator D = Contexts[I]->decls_begin(),
+ DEnd = Contexts[I]->decls_end();
D != DEnd; ++D) {
// Insert this declaration into the lookup structure, but only
// if it's semantically in its decl context. During non-lazy
// lookup building, this is implicitly enforced by addDecl.
if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
- if (D->getDeclContext() == DCtx)
+ if (D->getDeclContext() == Contexts[I])
makeDeclVisibleInContextImpl(ND, false);
// If this declaration is itself a transparent declaration context or
OpenPOWER on IntegriCloud