[cfe-commits] r121139 - in /cfe/trunk: lib/AST/ASTImporter.cpp test/ASTMerge/Inputs/category1.m test/ASTMerge/Inputs/category2.m

Douglas Gregor dgregor at apple.com
Tue Dec 7 07:32:12 PST 2010


Author: dgregor
Date: Tue Dec  7 09:32:12 2010
New Revision: 121139

URL: http://llvm.org/viewvc/llvm-project?rev=121139&view=rev
Log:
Implement ASTImporter support for Objective-C category implementations.

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/test/ASTMerge/Inputs/category1.m
    cfe/trunk/test/ASTMerge/Inputs/category2.m

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=121139&r1=121138&r2=121139&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Dec  7 09:32:12 2010
@@ -115,6 +115,7 @@
     Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D);
     Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
     Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
+    Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
     Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D);
     Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D);
     Decl *VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
@@ -3024,6 +3025,41 @@
   return ToIface;
 }
 
+Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
+  ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>(
+                                        Importer.Import(D->getCategoryDecl()));
+  if (!Category)
+    return 0;
+  
+  ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
+  if (!ToImpl) {
+    DeclContext *DC = Importer.ImportContext(D->getDeclContext());
+    if (!DC)
+      return 0;
+    
+    ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC,
+                                          Importer.Import(D->getLocation()),
+                                          Importer.Import(D->getIdentifier()),
+                                          Category->getClassInterface());
+    
+    DeclContext *LexicalDC = DC;
+    if (D->getDeclContext() != D->getLexicalDeclContext()) {
+      LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
+      if (!LexicalDC)
+        return 0;
+      
+      ToImpl->setLexicalDeclContext(LexicalDC);
+    }
+    
+    LexicalDC->addDecl(ToImpl);
+    Category->setImplementation(ToImpl);
+  }
+  
+  Importer.Imported(D, ToImpl);
+  ImportDeclContext(ToImpl);
+  return ToImpl;
+}
+
 Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
   // Find the corresponding interface.
   ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>(

Modified: cfe/trunk/test/ASTMerge/Inputs/category1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/category1.m?rev=121139&r1=121138&r2=121139&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/category1.m (original)
+++ cfe/trunk/test/ASTMerge/Inputs/category1.m Tue Dec  7 09:32:12 2010
@@ -23,3 +23,12 @@
 @interface I2 ()
 - (int)method3;
 @end
+
+// Category with implementation
+ at interface I2 (Cat3)
+ at end
+
+// Category with implementation
+ at interface I2 (Cat4)
+ at end
+

Modified: cfe/trunk/test/ASTMerge/Inputs/category2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/category2.m?rev=121139&r1=121138&r2=121139&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/category2.m (original)
+++ cfe/trunk/test/ASTMerge/Inputs/category2.m Tue Dec  7 09:32:12 2010
@@ -25,3 +25,11 @@
 @interface I2 ()
 - (float)method3;
 @end
+
+// Category with implementation
+ at interface I2 (Cat3)
+ at end
+
+// Category with implementation
+ at interface I2 (Cat5)
+ at end





More information about the cfe-commits mailing list