[cfe-commits] r96554 - in /cfe/trunk: lib/AST/ASTImporter.cpp test/ASTMerge/Inputs/interface1.m test/ASTMerge/Inputs/interface2.m

Douglas Gregor dgregor at apple.com
Wed Feb 17 18:04:09 PST 2010


Author: dgregor
Date: Wed Feb 17 20:04:09 2010
New Revision: 96554

URL: http://llvm.org/viewvc/llvm-project?rev=96554&view=rev
Log:
Implement import of forward declarations of Objective-C classes

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/test/ASTMerge/Inputs/interface1.m
    cfe/trunk/test/ASTMerge/Inputs/interface2.m

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=96554&r1=96553&r2=96554&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Feb 17 20:04:09 2010
@@ -99,7 +99,8 @@
     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 @@
   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
 //----------------------------------------------------------------------------

Modified: cfe/trunk/test/ASTMerge/Inputs/interface1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/interface1.m?rev=96554&r1=96553&r2=96554&view=diff

==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/interface1.m (original)
+++ cfe/trunk/test/ASTMerge/Inputs/interface1.m Wed Feb 17 20:04:09 2010
@@ -68,3 +68,8 @@
 @protocol P2 <P0>
 - (float)wibble:(int)a1 second:(int)a2;
 @end
+
+// Forward-declared interfaces
+ at class I10, I11;
+ at interface I12
+ at end

Modified: cfe/trunk/test/ASTMerge/Inputs/interface2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/interface2.m?rev=96554&r1=96553&r2=96554&view=diff

==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/interface2.m (original)
+++ cfe/trunk/test/ASTMerge/Inputs/interface2.m Wed Feb 17 20:04:09 2010
@@ -67,3 +67,8 @@
 @protocol P2 <P0>
 - (float)wibble:(int)a1 second:(int)a2;
 @end
+
+// Forward-declared interface
+ at class I12, I10;
+ at interface I11
+ at end





More information about the cfe-commits mailing list