aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-12-07 15:32:12 +0000
committerDouglas Gregor <dgregor@apple.com>2010-12-07 15:32:12 +0000
commit3daef29bf390dbdb3603748280afd5827d1811da (patch)
tree5450af5aa4ceae894c7a85ba4f76fb939f213064
parentf5fe2925b87cf382f2f13983c81679e38067122b (diff)
Implement ASTImporter support for Objective-C category implementations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121139 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ASTImporter.cpp36
-rw-r--r--test/ASTMerge/Inputs/category1.m9
-rw-r--r--test/ASTMerge/Inputs/category2.m8
3 files changed, 53 insertions, 0 deletions
diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp
index ffebbf349e..c5314059c0 100644
--- a/lib/AST/ASTImporter.cpp
+++ b/lib/AST/ASTImporter.cpp
@@ -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>(
diff --git a/test/ASTMerge/Inputs/category1.m b/test/ASTMerge/Inputs/category1.m
index ade1c6c66d..6d4fd8d9f2 100644
--- a/test/ASTMerge/Inputs/category1.m
+++ b/test/ASTMerge/Inputs/category1.m
@@ -23,3 +23,12 @@
@interface I2 ()
- (int)method3;
@end
+
+// Category with implementation
+@interface I2 (Cat3)
+@end
+
+// Category with implementation
+@interface I2 (Cat4)
+@end
+
diff --git a/test/ASTMerge/Inputs/category2.m b/test/ASTMerge/Inputs/category2.m
index f66c208680..646ebb557a 100644
--- a/test/ASTMerge/Inputs/category2.m
+++ b/test/ASTMerge/Inputs/category2.m
@@ -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