From: Douglas Gregor Date: Tue, 7 Dec 2010 15:32:12 +0000 (+0000) Subject: Implement ASTImporter support for Objective-C category implementations. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3daef29bf390dbdb3603748280afd5827d1811da;p=clang 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 --- 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( + 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( 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