]> granicus.if.org Git - clang/commitdiff
Patch to make ObjcImplementationDecl derived from TypeDecl and supprt legacy
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 25 Sep 2007 21:00:20 +0000 (21:00 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 25 Sep 2007 21:00:20 +0000 (21:00 +0000)
objective-c code with no @interface declaration.

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

Sema/SemaDecl.cpp
include/clang/AST/Decl.h
test/Sema/objc-legacy-implementation-1.m [new file with mode: 0644]

index 9a52874f79d73d383530da84a97cc91c0d4a9255..5470eb456bd326b974098eda4dd8361488daa40e 100644 (file)
@@ -1105,6 +1105,14 @@ Sema::DeclTy *Sema::ObjcStartClassImplementation(Scope *S,
   
   ObjcImplementationDecl* IMPDecl = 
     new ObjcImplementationDecl(AtClassImplLoc, ClassName, SDecl);
+  if (!IDecl) {
+    // Legacy case of @implementation with no corresponding @interface.
+    // Build, chain & install the interface decl into the identifier.
+    IDecl = new ObjcInterfaceDecl(AtClassImplLoc, 0, ClassName);
+    IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
+    ClassName->setFETokenInfo(IDecl);
+    
+  }
   
   // Check that there is no duplicate implementation of this class.
   bool err = false;
index 425e8711ea9029e2cc8b96a6ed11995ca5784466..7cb370b41cdb47dd3781ef0252ae0e7e1ce24f17 100644 (file)
@@ -858,7 +858,7 @@ public:
   static bool classof(const ObjcCategoryDecl *D) { return true; }
 };
   
-class ObjcImplementationDecl : public ScopedDecl {
+class ObjcImplementationDecl : public TypeDecl {
     
   /// Implementation Class's super class.
   ObjcInterfaceDecl *SuperClass;
@@ -878,7 +878,7 @@ class ObjcImplementationDecl : public ScopedDecl {
   public:
   ObjcImplementationDecl(SourceLocation L, IdentifierInfo *Id,
                          ObjcInterfaceDecl* superDecl)
-    : ScopedDecl(ObjcImplementation, L, Id, 0),
+    : TypeDecl(ObjcImplementation, L, Id, 0),
       SuperClass(superDecl),
       Ivars(0), NumIvars(-1),
       InsMethods(0), NumInsMethods(-1), ClsMethods(0), NumClsMethods(-1) {}
diff --git a/test/Sema/objc-legacy-implementation-1.m b/test/Sema/objc-legacy-implementation-1.m
new file mode 100644 (file)
index 0000000..c706ec7
--- /dev/null
@@ -0,0 +1,9 @@
+@implementation INTF // expected-warning {{cannot find interface declaration for 'INTF'}}
+@end
+
+INTF* pi;
+
+INTF* FUNC()
+{
+       return pi;
+}