]> granicus.if.org Git - clang/commitdiff
Implement import of forward declarations of Objective-C classes
authorDouglas Gregor <dgregor@apple.com>
Thu, 18 Feb 2010 02:04:09 +0000 (02:04 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 18 Feb 2010 02:04:09 +0000 (02:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96554 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTImporter.cpp
test/ASTMerge/Inputs/interface1.m
test/ASTMerge/Inputs/interface2.m

index cde3402f7aa7995895198e9116b0f8f1cc6cd5b4..b0d463bec72f9dc5c49cb991da4418cd8fcae617 100644 (file)
@@ -99,7 +99,8 @@ namespace {
     Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
     Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
     Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D);
-
+    Decl *VisitObjCClassDecl(ObjCClassDecl *D);
+                            
     // Importing statements
     Stmt *VisitStmt(Stmt *S);
 
@@ -2484,6 +2485,46 @@ Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
   return ToProperty;
 }
 
+Decl *ASTNodeImporter::VisitObjCClassDecl(ObjCClassDecl *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<ObjCInterfaceDecl *, 4> Interfaces;
+  llvm::SmallVector<SourceLocation, 4> Locations;
+  for (ObjCClassDecl::iterator From = D->begin(), FromEnd = D->end();
+       From != FromEnd; ++From) {
+    ObjCInterfaceDecl *ToIface
+      = cast_or_null<ObjCInterfaceDecl>(Importer.Import(From->getInterface()));
+    if (!ToIface)
+      continue;
+    
+    Interfaces.push_back(ToIface);
+    Locations.push_back(Importer.Import(From->getLocation()));
+  }
+  
+  ObjCClassDecl *ToClass = ObjCClassDecl::Create(Importer.getToContext(), DC,
+                                                 Loc, 
+                                                 Interfaces.data(),
+                                                 Locations.data(),
+                                                 Interfaces.size());
+  ToClass->setLexicalDeclContext(LexicalDC);
+  LexicalDC->addDecl(ToClass);
+  Importer.Imported(D, ToClass);
+  return ToClass;
+}
+
 //----------------------------------------------------------------------------
 // Import Statements
 //----------------------------------------------------------------------------
index a508bc159bd2eafe9d453c7bd213684a5c692f68..029dad329b5f69bc7525ee0fbf35512dfac0ebbe 100644 (file)
@@ -68,3 +68,8 @@
 @protocol P2 <P0>
 - (float)wibble:(int)a1 second:(int)a2;
 @end
+
+// Forward-declared interfaces
+@class I10, I11;
+@interface I12
+@end
index d79f77d92a2f6138e6e4d56bf1e096b947bb8237..30de98160cce33e0876bd63d5c13c95ba7b59194 100644 (file)
@@ -67,3 +67,8 @@
 @protocol P2 <P0>
 - (float)wibble:(int)a1 second:(int)a2;
 @end
+
+// Forward-declared interface
+@class I12, I10;
+@interface I11
+@end