From: Fariborz Jahanian Date: Wed, 31 Oct 2007 18:48:14 +0000 (+0000) Subject: Fixed problem with rewriting stand-alone @implementation (with no matching @interface). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a3ca1b35a7121aea0bf465a192dce748465e10f;p=clang Fixed problem with rewriting stand-alone @implementation (with no matching @interface). A new test case added. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43568 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/Sema.h b/Sema/Sema.h index 3b8b5e98b3..32ab40d71f 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -259,7 +259,8 @@ private: /// CheckImplementationIvars - This routine checks if the instance variables /// listed in the implelementation match those listed in the interface. void CheckImplementationIvars(ObjcImplementationDecl *ImpDecl, - ObjcIvarDecl **Fields, unsigned nIvars); + ObjcIvarDecl **Fields, unsigned nIvars, + SourceLocation Loc); /// ImplMethodsVsClassMethods - This is main routine to warn if any method /// remains unimplemented in the @implementation class. diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index ea73db5088..66ece4149a 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1253,10 +1253,12 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation( if (!IDecl) { // Legacy case of @implementation with no corresponding @interface. // Build, chain & install the interface decl into the identifier. - IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, ClassName); + IDecl = new ObjcInterfaceDecl(AtClassImplLoc, 0, ClassName, + false, true); IDecl->setNext(ClassName->getFETokenInfo()); ClassName->setFETokenInfo(IDecl); IDecl->setSuperClass(SDecl); + IDecl->setLocEnd(ClassLoc); // Remember that this needs to be removed when the scope is popped. TUScope->AddDecl(IDecl); @@ -1273,7 +1275,8 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation( } void Sema::CheckImplementationIvars(ObjcImplementationDecl *ImpDecl, - ObjcIvarDecl **ivars, unsigned numIvars) { + ObjcIvarDecl **ivars, unsigned numIvars, + SourceLocation RBrace) { assert(ImpDecl && "missing implementation decl"); ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(ImpDecl->getIdentifier()); if (!IDecl) @@ -1282,7 +1285,7 @@ void Sema::CheckImplementationIvars(ObjcImplementationDecl *ImpDecl, /// (legacy objective-c @implementation decl without an @interface decl). /// Add implementations's ivar to the synthesize class's ivar list. if (IDecl->ImplicitInterfaceDecl()) { - IDecl->addInstanceVariablesToClass(ivars, numIvars, SourceLocation()); + IDecl->addInstanceVariablesToClass(ivars, numIvars, RBrace); return; } @@ -1795,7 +1798,7 @@ void Sema::ActOnFields(Scope* S, cast(static_cast(RecDecl)); assert(IMPDecl && "ActOnFields - missing ObjcImplementationDecl"); IMPDecl->ObjcAddInstanceVariablesToClassImpl(ClsFields, RecFields.size()); - CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size()); + CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac); } } } diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 0ca98bb6ec..dcff5ea36e 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -72,19 +72,21 @@ class ObjcInterfaceDecl : public TypeDecl { /// List of categories defined for this class. ObjcCategoryDecl *CategoryList; - bool ForwardDecl; // declared with @class. + bool ForwardDecl:1; // declared with @class. + bool InternalInterface:1; // true - no @interface for @implementation SourceLocation EndLoc; // marks the '>', '}', or identifier. SourceLocation AtEndLoc; // marks the end of the entire interface. public: ObjcInterfaceDecl(SourceLocation atLoc, unsigned numRefProtos, - IdentifierInfo *Id, bool FD = false) + IdentifierInfo *Id, bool FD = false, + bool isInternal = false) : TypeDecl(ObjcInterface, atLoc, Id, 0), SuperClass(0), ReferencedProtocols(0), NumReferencedProtocols(-1), Ivars(0), NumIvars(-1), InstanceMethods(0), NumInstanceMethods(-1), ClassMethods(0), NumClassMethods(-1), - CategoryList(0), ForwardDecl(FD) { + CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal) { AllocIntfRefProtocols(numRefProtos); } @@ -148,7 +150,7 @@ public: /// ImplicitInterfaceDecl - check that this is an implicitely declared /// ObjcInterfaceDecl node. This is for legacy objective-c @implementation /// declaration without an @interface declaration. - bool ImplicitInterfaceDecl() const { return getLocation().isInvalid(); } + bool ImplicitInterfaceDecl() const { return InternalInterface; } static bool classof(const Decl *D) { return D->getKind() == ObjcInterface; } static bool classof(const ObjcInterfaceDecl *D) { return true; } diff --git a/test/Sema/ivar-encoding-2.m b/test/Sema/ivar-encoding-2.m new file mode 100644 index 0000000000..424b30fb6f --- /dev/null +++ b/test/Sema/ivar-encoding-2.m @@ -0,0 +1,12 @@ +// RUN: clang -rewrite-test %s + +@implementation Intf +{ + id ivar; + id ivar1[12]; + + id **ivar3; + + id (*ivar4) (id, id); +} +@end