[cfe-commits] r147780 - in /cfe/trunk: lib/Serialization/ASTReaderDecl.cpp test/Modules/Inputs/namespaces-left.h test/Modules/Inputs/namespaces-right.h test/Modules/namespaces.cpp

Douglas Gregor dgregor at apple.com
Mon Jan 9 09:38:47 PST 2012


Author: dgregor
Date: Mon Jan  9 11:38:47 2012
New Revision: 147780

URL: http://llvm.org/viewvc/llvm-project?rev=147780&view=rev
Log:
Implement merging of namespace-scope declarations across modules, so
that we can merge, for example, two occurrences of

  namespace N { void f(); }

in two disjoint modules.

Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/test/Modules/Inputs/namespaces-left.h
    cfe/trunk/test/Modules/Inputs/namespaces-right.h
    cfe/trunk/test/Modules/namespaces.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=147780&r1=147779&r2=147780&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Jan  9 11:38:47 2012
@@ -1741,14 +1741,14 @@
 }
 
 ASTDeclReader::FindExistingResult::~FindExistingResult() {
-  if (!AddResult)
+  if (!AddResult || Existing)
     return;
   
   DeclContext *DC = New->getDeclContext()->getRedeclContext();
   if (DC->isTranslationUnit() && Reader.SemaObj) {
-    if (!Existing) {
-      Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName());
-    }
+    Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName());
+  } else if (DC->isNamespace()) {
+    DC->addDecl(New);
   }
 }
 
@@ -1775,7 +1775,13 @@
     }
   }
 
-  // FIXME: Search in the DeclContext.
+  if (DC->isNamespace()) {
+    for (DeclContext::lookup_result R = DC->lookup(Name);
+         R.first != R.second; ++R.first) {
+      if (isSameEntity(*R.first, D))
+        return FindExistingResult(Reader, D, *R.first);
+    }
+  }
   
   return FindExistingResult(Reader, D, /*Existing=*/0);
 }

Modified: cfe/trunk/test/Modules/Inputs/namespaces-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/namespaces-left.h?rev=147780&r1=147779&r2=147780&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/namespaces-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/namespaces-left.h Mon Jan  9 11:38:47 2012
@@ -25,3 +25,15 @@
 namespace N7 {
   int &f(int);
 }
+
+namespace N8 {
+  int &f(int);
+}
+
+namespace N9 {
+  int &f(int);
+}
+
+namespace N10 {
+  int &f(int);
+}

Modified: cfe/trunk/test/Modules/Inputs/namespaces-right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/namespaces-right.h?rev=147780&r1=147779&r2=147780&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/namespaces-right.h (original)
+++ cfe/trunk/test/Modules/Inputs/namespaces-right.h Mon Jan  9 11:38:47 2012
@@ -27,3 +27,15 @@
 namespace N7 {
   double &f(double);
 }
+
+namespace N8 {
+  int &f(int);
+}
+
+namespace N9 {
+  int &f(int);
+}
+
+namespace N10 {
+  int &f(int);
+}

Modified: cfe/trunk/test/Modules/namespaces.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/namespaces.cpp?rev=147780&r1=147779&r2=147780&view=diff
==============================================================================
--- cfe/trunk/test/Modules/namespaces.cpp (original)
+++ cfe/trunk/test/Modules/namespaces.cpp Mon Jan  9 11:38:47 2012
@@ -5,6 +5,8 @@
   char &f(char);
 }
 
+namespace N8 { }
+
 @import namespaces_left;
 @import namespaces_right;
 
@@ -23,6 +25,10 @@
   char &f(char);
 }
 
+namespace N10 { 
+  int &f(int);
+}
+
 void testMerged() {
   int &ir1 = N5::f(17);
   int &ir2 = N6::f(17);
@@ -34,3 +40,10 @@
   char &cr2 = N6::f('b');
 }
 
+// Test merging of declarations within namespaces that themselves were
+// merged without a common first declaration.
+void testMergedMerged() {
+  int &ir1 = N8::f(17);
+  int &ir2 = N9::f(17);
+  int &ir3 = N10::f(17);
+}





More information about the cfe-commits mailing list