]> granicus.if.org Git - clang/commitdiff
Implement ASTImporter support for Objective-C category implementations.
authorDouglas Gregor <dgregor@apple.com>
Tue, 7 Dec 2010 15:32:12 +0000 (15:32 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 7 Dec 2010 15:32:12 +0000 (15:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121139 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTImporter.cpp
test/ASTMerge/Inputs/category1.m
test/ASTMerge/Inputs/category2.m

index ffebbf349ef72955801e34221a0e649995d01091..c5314059c088ced87e63cacff52a7cddd65155fc 100644 (file)
@@ -115,6 +115,7 @@ namespace {
     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 @@ Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
   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>(
index ade1c6c66da30530150ce7737ee0422f65a4c922..6d4fd8d9f286c68b22abc378a84f41dddb9e0f7f 100644 (file)
 @interface I2 ()
 - (int)method3;
 @end
+
+// Category with implementation
+@interface I2 (Cat3)
+@end
+
+// Category with implementation
+@interface I2 (Cat4)
+@end
+
index f66c208680c2a19a5761668a6ecce50af04cede8..646ebb557ab37ff6f05fa45c2461ab21da04ce5d 100644 (file)
@@ -25,3 +25,11 @@ typedef int Int;
 @interface I2 ()
 - (float)method3;
 @end
+
+// Category with implementation
+@interface I2 (Cat3)
+@end
+
+// Category with implementation
+@interface I2 (Cat5)
+@end