From: Fariborz Jahanian Date: Tue, 24 Sep 2013 17:03:07 +0000 (+0000) Subject: Revert my patch in r191155 to allow forward X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2330df43c89dfbcf888a1b0d608f71546f29b6cf;p=clang Revert my patch in r191155 to allow forward class/protocol decls in @implementation and fixup modern rewriter to handle that. // rdar://15066233 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191311 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/lib/Rewrite/Frontend/RewriteModernObjC.cpp index ecd509610a..af9cda3fad 100644 --- a/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -1066,16 +1066,19 @@ void RewriteModernObjC::RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl void RewriteModernObjC::RewriteForwardClassDecl(DeclGroupRef D) { std::string typedefString; for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { - ObjCInterfaceDecl *ForwardDecl = cast(*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(*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(*I), typedefString); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index ec82221289..b938bd6f8b 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -809,12 +809,6 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, unsigned NumElts, AttributeList *attrList) { SmallVector DeclsInGroup; - if (isa(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(SourceLocation AtClassLoc, SourceLocation *IdentLocs, unsigned NumElts) { SmallVector DeclsInGroup; - if (isa(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 diff --git a/test/Parser/missing-end-4.m b/test/Parser/missing-end-4.m index 058daf91f4..8a96e64421 100644 --- a/test/Parser/missing-end-4.m +++ b/test/Parser/missing-end-4.m @@ -32,9 +32,9 @@ @interface I @end @implementation I -@protocol P; // expected-error {{Objective-C declarations may only appear in global scope}} -@class C; // expected-error {{Objective-C declarations may only appear in global scope}} -- (C

*) MyMeth {} // expected-error {{expected a type}} +@protocol P; // forward declarations of protocols in @implementations is allowed +@class C; // forward declarations of classes in @implementations is allowed +- (C

*) MyMeth {} @end @interface I2 {} @@ -47,5 +47,5 @@ @implementation I3 - Meth {} + Cls {} -@protocol P3; // expected-error {{Objective-C declarations may only appear in global scope}} +@protocol P3; @end diff --git a/test/Rewriter/rewrite-forward-class.mm b/test/Rewriter/rewrite-forward-class.mm index 9f4e7e21e8..3d3ef3e6c9 100644 --- a/test/Rewriter/rewrite-forward-class.mm +++ b/test/Rewriter/rewrite-forward-class.mm @@ -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 +@interface ISDPropertyChangeGroup +@end + +@implementation ISDPropertyChangeGroup +@class ISDClientState; +- (id)lastModifiedGeneration : (ISDClientState *) obj +{ + return obj ; +} +@end