diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-09 17:30:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-09 17:30:44 +0000 |
commit | cfe7dc6b2f694ca0a18698e830a0dcb4c7dfe979 (patch) | |
tree | a3b3455b0d5e13ee38987819113ea8dd98de2a7d /clang/lib/Serialization/ASTReaderDecl.cpp | |
parent | f9d0cc016080e217daeb6e200cbd9839bf5aa78b (diff) | |
download | bcm5719-llvm-cfe7dc6b2f694ca0a18698e830a0dcb4c7dfe979.tar.gz bcm5719-llvm-cfe7dc6b2f694ca0a18698e830a0dcb4c7dfe979.zip |
Implement redeclaration merging for namespaces defined in distinct
modules. Teach name lookup into namespaces to search in each of the
merged DeclContexts as well as the (now-primary) DeclContext. This
supports the common case where two different modules put something
into the same namespace.
llvm-svn: 147778
Diffstat (limited to 'clang/lib/Serialization/ASTReaderDecl.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 56e2d085e38..ffd768a94d2 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -369,6 +369,9 @@ void ASTDeclReader::VisitDecl(Decl *D) { // Determine whether this declaration is part of a (sub)module. If so, it // may not yet be visible. if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) { + // Store the owning submodule ID in the declaration. + D->setOwningModuleID(SubmoduleID); + // Module-private declarations are never visible, so there is no work to do. if (!D->isModulePrivate()) { if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { @@ -972,7 +975,8 @@ void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { D->setInline(Record[Idx++]); D->LocStart = ReadSourceLocation(Record, Idx); D->RBraceLoc = ReadSourceLocation(Record, Idx); - + mergeRedeclarable(D, Redecl); + if (Redecl.getFirstID() == ThisDeclID) { // FIXME: If there's already an anonymous namespace, do we merge it with // this one? Or do we, when loading modules, just forget about anonymous @@ -1232,7 +1236,7 @@ ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { RedeclKind Kind = (RedeclKind)Record[Idx++]; // Determine the first declaration ID. - DeclID FirstDeclID; + DeclID FirstDeclID = 0; switch (Kind) { case FirstDeclaration: { FirstDeclID = ThisDeclID; @@ -1489,7 +1493,7 @@ ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { enum RedeclKind { FirstDeclaration = 0, FirstInFile, PointsToPrevious }; RedeclKind Kind = (RedeclKind)Record[Idx++]; - DeclID FirstDeclID; + DeclID FirstDeclID = 0; switch (Kind) { case FirstDeclaration: FirstDeclID = ThisDeclID; @@ -1545,6 +1549,13 @@ void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *D, D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(ExistingCanon); + // When we merge a namespace, update its pointer to the first namespace. + if (NamespaceDecl *Namespace + = dyn_cast<NamespaceDecl>(static_cast<T*>(D))) { + Namespace->AnonOrFirstNamespaceAndInline.setPointer( + static_cast<NamespaceDecl *>(static_cast<void*>(ExistingCanon))); + } + // Don't introduce DCanon into the set of pending declaration chains. Redecl.suppress(); @@ -1719,6 +1730,12 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { VarX->getASTContext().hasSameType(VarX->getType(), VarY->getType()); } + // Namespaces with the same name and inlinedness match. + if (NamespaceDecl *NamespaceX = dyn_cast<NamespaceDecl>(X)) { + NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y); + return NamespaceX->isInline() == NamespaceY->isInline(); + } + // FIXME: Many other cases to implement. return false; } |