summaryrefslogtreecommitdiffstats
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
commit4da9d68da086e648bf67acbbb4d896b7e7567858 (patch)
treef1dbf9ba055cff6acbc73a237ac5e35c9902284c
parent0017c5fa92ad3b10e15fd34f3865e8e5b850a5ed (diff)
downloadbcm5719-llvm-4da9d68da086e648bf67acbbb4d896b7e7567858.tar.gz
bcm5719-llvm-4da9d68da086e648bf67acbbb4d896b7e7567858.zip
Implement ASTImporter support for Objective-C category implementations.
llvm-svn: 121139
-rw-r--r--clang/lib/AST/ASTImporter.cpp36
-rw-r--r--clang/test/ASTMerge/Inputs/category1.m9
-rw-r--r--clang/test/ASTMerge/Inputs/category2.m8
3 files changed, 53 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index ffebbf349ef..c5314059c08 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/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/clang/test/ASTMerge/Inputs/category1.m b/clang/test/ASTMerge/Inputs/category1.m
index ade1c6c66da..6d4fd8d9f28 100644
--- a/clang/test/ASTMerge/Inputs/category1.m
+++ b/clang/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/clang/test/ASTMerge/Inputs/category2.m b/clang/test/ASTMerge/Inputs/category2.m
index f66c208680c..646ebb557ab 100644
--- a/clang/test/ASTMerge/Inputs/category2.m
+++ b/clang/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
OpenPOWER on IntegriCloud