[cfe-commits] r43568 - in /cfe/trunk: Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/DeclObjC.h test/Sema/ivar-encoding-2.m

Fariborz Jahanian fjahanian at apple.com
Wed Oct 31 11:48:15 PDT 2007


Author: fjahanian
Date: Wed Oct 31 13:48:14 2007
New Revision: 43568

URL: http://llvm.org/viewvc/llvm-project?rev=43568&view=rev
Log:
Fixed problem with rewriting stand-alone @implementation (with no matching @interface).
A new test case added.

Added:
    cfe/trunk/test/Sema/ivar-encoding-2.m
Modified:
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=43568&r1=43567&r2=43568&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Oct 31 13:48:14 2007
@@ -259,7 +259,8 @@
   /// 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.

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43568&r1=43567&r2=43568&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Oct 31 13:48:14 2007
@@ -1253,10 +1253,12 @@
   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<ScopedDecl>());
     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 @@
 }
 
 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 @@
   /// (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 @@
         cast<ObjcImplementationDecl>(static_cast<Decl*>(RecDecl));
       assert(IMPDecl && "ActOnFields - missing ObjcImplementationDecl");
       IMPDecl->ObjcAddInstanceVariablesToClassImpl(ClsFields, RecFields.size());
-      CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size());
+      CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
     }
   }
 }

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=43568&r1=43567&r2=43568&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Wed Oct 31 13:48:14 2007
@@ -72,19 +72,21 @@
   /// 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 @@
   /// 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; }

Added: cfe/trunk/test/Sema/ivar-encoding-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ivar-encoding-2.m?rev=43568&view=auto

==============================================================================
--- cfe/trunk/test/Sema/ivar-encoding-2.m (added)
+++ cfe/trunk/test/Sema/ivar-encoding-2.m Wed Oct 31 13:48:14 2007
@@ -0,0 +1,12 @@
+// RUN: clang -rewrite-test %s
+
+ at implementation Intf
+{
+  id ivar;
+  id ivar1[12];
+
+  id **ivar3;
+
+  id (*ivar4) (id, id);
+}
+ at end





More information about the cfe-commits mailing list