]> granicus.if.org Git - clang/commitdiff
Fixed problem with rewriting stand-alone @implementation (with no matching @interface).
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 31 Oct 2007 18:48:14 +0000 (18:48 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 31 Oct 2007 18:48:14 +0000 (18:48 +0000)
A new test case added.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43568 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/Sema.h
Sema/SemaDecl.cpp
include/clang/AST/DeclObjC.h
test/Sema/ivar-encoding-2.m [new file with mode: 0644]

index 3b8b5e98b37d11f6f87a30276befad62d42b629e..32ab40d71f3d50f5e44ac1dc787ca167bbbdc252 100644 (file)
@@ -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.
index ea73db508879709fff802e42886799161129fac5..66ece4149acad663d354b89350285e99156071e9 100644 (file)
@@ -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<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 @@ 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<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);
     }
   }
 }
index 0ca98bb6eca7f12ba56f783706665f5e9a353e9b..dcff5ea36efbe7835ff42789f0adeff178635fb6 100644 (file)
@@ -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 (file)
index 0000000..424b30f
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: clang -rewrite-test %s
+
+@implementation Intf
+{
+  id ivar;
+  id ivar1[12];
+
+  id **ivar3;
+
+  id (*ivar4) (id, id);
+}
+@end