r191311 - Revert my patch in r191155 to allow forward

Fariborz Jahanian fjahanian at apple.com
Tue Sep 24 10:03:07 PDT 2013


Author: fjahanian
Date: Tue Sep 24 12:03:07 2013
New Revision: 191311

URL: http://llvm.org/viewvc/llvm-project?rev=191311&view=rev
Log:
Revert my patch in r191155 to allow forward
class/protocol decls in @implementation and
fixup modern rewriter to handle that.
// rdar://15066233

Modified:
    cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/Parser/missing-end-4.m
    cfe/trunk/test/Rewriter/rewrite-forward-class.mm

Modified: cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp?rev=191311&r1=191310&r2=191311&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/RewriteModernObjC.cpp Tue Sep 24 12:03:07 2013
@@ -1066,16 +1066,19 @@ void RewriteModernObjC::RewriteForwardCl
 void RewriteModernObjC::RewriteForwardClassDecl(DeclGroupRef D) {
   std::string typedefString;
   for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
-    ObjCInterfaceDecl *ForwardDecl = cast<ObjCInterfaceDecl>(*I);
-    if (I == D.begin()) {
-      // Translate to typedef's that forward reference structs with the same name
-      // as the class. As a convenience, we include the original declaration
-      // as a comment.
-      typedefString += "// @class ";
-      typedefString += ForwardDecl->getNameAsString();
-      typedefString += ";";
+    if (ObjCInterfaceDecl *ForwardDecl = dyn_cast<ObjCInterfaceDecl>(*I)) {
+      if (I == D.begin()) {
+        // Translate to typedef's that forward reference structs with the same name
+        // as the class. As a convenience, we include the original declaration
+        // as a comment.
+        typedefString += "// @class ";
+        typedefString += ForwardDecl->getNameAsString();
+        typedefString += ";";
+      }
+      RewriteOneForwardClassDecl(ForwardDecl, typedefString);
     }
-    RewriteOneForwardClassDecl(ForwardDecl, typedefString);
+    else
+      HandleTopLevelSingleDecl(*I);
   }
   DeclGroupRef::iterator I = D.begin();
   RewriteForwardClassEpilogue(cast<ObjCInterfaceDecl>(*I), typedefString);

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=191311&r1=191310&r2=191311&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Sep 24 12:03:07 2013
@@ -809,12 +809,6 @@ Sema::ActOnForwardProtocolDeclaration(So
                                       unsigned NumElts,
                                       AttributeList *attrList) {
   SmallVector<Decl *, 8> DeclsInGroup;
-  if (isa<ObjCContainerDecl>(CurContext)) {
-    Diag(AtProtocolLoc, 
-         diag::err_objc_decls_may_only_appear_in_global_scope);
-    return BuildDeclaratorGroup(DeclsInGroup, false);
-  }
-
   for (unsigned i = 0; i != NumElts; ++i) {
     IdentifierInfo *Ident = IdentList[i].first;
     ObjCProtocolDecl *PrevDecl = LookupProtocol(Ident, IdentList[i].second,
@@ -1933,12 +1927,6 @@ Sema::ActOnForwardClassDeclaration(Sourc
                                    SourceLocation *IdentLocs,
                                    unsigned NumElts) {
   SmallVector<Decl *, 8> DeclsInGroup;
-  if (isa<ObjCContainerDecl>(CurContext)) {
-    Diag(AtClassLoc, 
-         diag::err_objc_decls_may_only_appear_in_global_scope);
-    return BuildDeclaratorGroup(DeclsInGroup, false);
-  }
-
   for (unsigned i = 0; i != NumElts; ++i) {
     // Check for another declaration kind with the same name.
     NamedDecl *PrevDecl

Modified: cfe/trunk/test/Parser/missing-end-4.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/missing-end-4.m?rev=191311&r1=191310&r2=191311&view=diff
==============================================================================
--- cfe/trunk/test/Parser/missing-end-4.m (original)
+++ cfe/trunk/test/Parser/missing-end-4.m Tue Sep 24 12:03:07 2013
@@ -32,9 +32,9 @@
 @interface I
 @end
 @implementation I
- at protocol P; // expected-error {{Objective-C declarations may only appear in global scope}}
- at class C; // expected-error {{Objective-C declarations may only appear in global scope}}
-- (C<P>*) MyMeth {} // expected-error {{expected a type}}
+ at protocol P; // forward declarations of protocols in @implementations is allowed
+ at class C; // forward declarations of classes in @implementations is allowed
+- (C<P>*) MyMeth {}
 @end
 
 @interface I2 {}
@@ -47,5 +47,5 @@
 @implementation I3
 - Meth {}
 + Cls {}
- at protocol P3; // expected-error {{Objective-C declarations may only appear in global scope}}
+ at protocol P3;
 @end

Modified: cfe/trunk/test/Rewriter/rewrite-forward-class.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-forward-class.mm?rev=191311&r1=191310&r2=191311&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-forward-class.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-forward-class.mm Tue Sep 24 12:03:07 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-runtime=macosx-fragile-10.5 %s -o %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
 
 extern "C" {
@@ -42,3 +42,14 @@ int I,J,K;
 };
 
 
+// rdar://15027032
+ at interface ISDPropertyChangeGroup
+ at end
+
+ at implementation ISDPropertyChangeGroup
+ at class ISDClientState;
+- (id)lastModifiedGeneration : (ISDClientState *) obj
+{
+  return obj ;
+}
+ at end





More information about the cfe-commits mailing list