[cfe-commits] r96555 - 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:12:22 PST 2010


Author: dgregor
Date: Wed Feb 17 20:12:22 2010
New Revision: 96555

URL: http://llvm.org/viewvc/llvm-project?rev=96555&view=rev
Log:
AST import for forward declarations of Objective-C protocols

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=96555&r1=96554&r2=96555&view=diff

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

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

==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/interface1.m (original)
+++ cfe/trunk/test/ASTMerge/Inputs/interface1.m Wed Feb 17 20:12:22 2010
@@ -73,3 +73,9 @@
 @class I10, I11;
 @interface I12
 @end
+
+// Forward-declared protocols
+ at protocol P3, P5;
+ at protocol P4
+- (double)honk:(int)a;
+ 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=96555&r1=96554&r2=96555&view=diff

==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/interface2.m (original)
+++ cfe/trunk/test/ASTMerge/Inputs/interface2.m Wed Feb 17 20:12:22 2010
@@ -72,3 +72,9 @@
 @class I12, I10;
 @interface I11
 @end
+
+// Forward-declared protocols
+ at protocol P3, P4;
+ at protocol P5
+- (double)honk:(int)a;
+ at end





More information about the cfe-commits mailing list