summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-02-18 02:12:22 +0000
committerDouglas Gregor <dgregor@apple.com>2010-02-18 02:12:22 +0000
commit8661a72b483676235b414b23e4a7a739c63dd9e2 (patch)
treee58667154b02b7f142b71b1ca65dd09da9326637
parent06537af8738beee2494295c0929515e6764ef8e3 (diff)
downloadbcm5719-llvm-8661a72b483676235b414b23e4a7a739c63dd9e2.tar.gz
bcm5719-llvm-8661a72b483676235b414b23e4a7a739c63dd9e2.zip
AST import for forward declarations of Objective-C protocols
llvm-svn: 96555
-rw-r--r--clang/lib/AST/ASTImporter.cpp45
-rw-r--r--clang/test/ASTMerge/Inputs/interface1.m6
-rw-r--r--clang/test/ASTMerge/Inputs/interface2.m6
3 files changed, 57 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index b0d463bec72..e064e78c1ce 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -99,6 +99,7 @@ namespace {
Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D);
+ Decl *VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
Decl *VisitObjCClassDecl(ObjCClassDecl *D);
// Importing statements
@@ -2485,6 +2486,50 @@ Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
return ToProperty;
}
+Decl *
+ASTNodeImporter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
+ // Import the context of this declaration.
+ DeclContext *DC = Importer.ImportContext(D->getDeclContext());
+ if (!DC)
+ return 0;
+
+ DeclContext *LexicalDC = DC;
+ if (D->getDeclContext() != D->getLexicalDeclContext()) {
+ LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
+ if (!LexicalDC)
+ return 0;
+ }
+
+ // Import the location of this declaration.
+ SourceLocation Loc = Importer.Import(D->getLocation());
+
+ llvm::SmallVector<ObjCProtocolDecl *, 4> Protocols;
+ llvm::SmallVector<SourceLocation, 4> Locations;
+ ObjCForwardProtocolDecl::protocol_loc_iterator FromProtoLoc
+ = D->protocol_loc_begin();
+ for (ObjCForwardProtocolDecl::protocol_iterator FromProto
+ = D->protocol_begin(), FromProtoEnd = D->protocol_end();
+ FromProto != FromProtoEnd;
+ ++FromProto, ++FromProtoLoc) {
+ ObjCProtocolDecl *ToProto
+ = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
+ if (!ToProto)
+ continue;
+
+ Protocols.push_back(ToProto);
+ Locations.push_back(Importer.Import(*FromProtoLoc));
+ }
+
+ ObjCForwardProtocolDecl *ToForward
+ = ObjCForwardProtocolDecl::Create(Importer.getToContext(), DC, Loc,
+ Protocols.data(), Protocols.size(),
+ Locations.data());
+ ToForward->setLexicalDeclContext(LexicalDC);
+ LexicalDC->addDecl(ToForward);
+ Importer.Imported(D, ToForward);
+ return ToForward;
+}
+
Decl *ASTNodeImporter::VisitObjCClassDecl(ObjCClassDecl *D) {
// Import the context of this declaration.
DeclContext *DC = Importer.ImportContext(D->getDeclContext());
diff --git a/clang/test/ASTMerge/Inputs/interface1.m b/clang/test/ASTMerge/Inputs/interface1.m
index 029dad329b5..7e9935db7c7 100644
--- a/clang/test/ASTMerge/Inputs/interface1.m
+++ b/clang/test/ASTMerge/Inputs/interface1.m
@@ -73,3 +73,9 @@
@class I10, I11;
@interface I12
@end
+
+// Forward-declared protocols
+@protocol P3, P5;
+@protocol P4
+- (double)honk:(int)a;
+@end
diff --git a/clang/test/ASTMerge/Inputs/interface2.m b/clang/test/ASTMerge/Inputs/interface2.m
index 30de98160cc..bef7fb838c0 100644
--- a/clang/test/ASTMerge/Inputs/interface2.m
+++ b/clang/test/ASTMerge/Inputs/interface2.m
@@ -72,3 +72,9 @@
@class I12, I10;
@interface I11
@end
+
+// Forward-declared protocols
+@protocol P3, P4;
+@protocol P5
+- (double)honk:(int)a;
+@end
OpenPOWER on IntegriCloud