]> granicus.if.org Git - clang/commitdiff
fe support for objc2's nonfragile-abi synthesized ivars.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 31 Mar 2009 00:06:29 +0000 (00:06 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 31 Mar 2009 00:06:29 +0000 (00:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68077 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/ASTContext.cpp
lib/AST/DeclObjC.cpp
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/property-nonfragile-abi.m
test/SemaObjC/synthesized-ivar.m [new file with mode: 0644]

index 8ca0a378d766472223c60971f7c0c98d46845d5c..76e4c0211e30f4277c2343d39e3c5eef3193a8b3 100644 (file)
@@ -1009,6 +1009,7 @@ private:
   
   ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
   ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
+  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
 
   ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 
                    QualType T)
@@ -1016,7 +1017,7 @@ private:
       PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
       GetterName(Selector()), 
       SetterName(Selector()),
-      GetterMethodDecl(0), SetterMethodDecl(0) {}
+      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
 public:
   static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, 
                                   SourceLocation L, 
@@ -1074,6 +1075,13 @@ public:
     return PropertyControl(PropertyImplementation);
   }  
   
+  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
+    PropertyIvarDecl = Ivar;
+  }
+  ObjCIvarDecl *getPropertyIvarDecl() const {
+    return PropertyIvarDecl;
+  }
+  
   static bool classof(const Decl *D) {
     return D->getKind() == ObjCProperty;
   }
@@ -1091,7 +1099,6 @@ public:
     Dynamic
   };
 private:
-  unsigned IvarKind : 1;
   SourceLocation AtLoc;   // location of @synthesize or @dynamic
   /// Property declaration being implemented
   ObjCPropertyDecl *PropertyDecl;
@@ -1103,7 +1110,7 @@ private:
                        ObjCPropertyDecl *property, 
                        Kind PK, 
                        ObjCIvarDecl *ivarDecl)
-    : Decl(ObjCPropertyImpl, DC, L), IvarKind(false), AtLoc(atLoc), 
+    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc), 
       PropertyDecl(property), PropertyIvarDecl(ivarDecl) {
     assert (PK == Dynamic || PropertyIvarDecl);
   }
@@ -1128,16 +1135,6 @@ public:
   ObjCIvarDecl *getPropertyIvarDecl() const {
     return PropertyIvarDecl;
   }
-  void SetPropertyIvarDecl(ObjCIvarDecl *Ivar) {
-    assert(PropertyIvarDecl && "PropertyIvarDecl is already defined");
-    PropertyIvarDecl = Ivar;
-  }
-  void SetIvarSynthesized() {
-    IvarKind = true;
-  }
-  bool IsIvarSynthesized() const {
-    return IvarKind;
-  }
   
   static bool classof(const Decl *D) {
     return D->getKind() == ObjCPropertyImpl;
index bb1795472781e1d40dec49f50e684e039699724b..b62438cd61a765d3ed1b9ef1f249084ce3d9459f 100644 (file)
@@ -608,6 +608,13 @@ void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
     if (!IVDecl->isInvalidDecl())
       Fields.push_back(cast<FieldDecl>(IVDecl));
   }
+  // look into properties.
+  for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(),
+       E = OI->prop_end(); I != E; ++I) {
+    ObjCPropertyDecl *PDecl = (*I);
+    if (ObjCIvarDecl *IV = PDecl->getPropertyIvarDecl())
+      Fields.push_back(cast<FieldDecl>(IV));
+  }
 }
 
 /// addRecordToClass - produces record info. for the class for its
index 4d2fcb69ac7ffe86e504a77094de127ebdb023b8..855764fdbd31def9a2ada2413f07f426d98260dc 100644 (file)
@@ -137,6 +137,16 @@ ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
         return *I;
       }
     }
+    // look into properties.
+    for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(),
+         E = ClassDecl->prop_end(); I != E; ++I) {
+      ObjCPropertyDecl *PDecl = (*I);
+      if (ObjCIvarDecl *IV = PDecl->getPropertyIvarDecl())
+        if (IV->getIdentifier() == ID) {
+          clsDeclared = ClassDecl;
+          return IV;
+        }
+    }
     ClassDecl = ClassDecl->getSuperClass();
   }
   return NULL;
index 18e3e4f9097202555b930d41a22678eccb6f1e9b..c68eede1045f0e96e4bcf80e7469a700037fe745 100644 (file)
@@ -1765,17 +1765,22 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
     // @synthesize
     if (!PropertyIvar)
       PropertyIvar = PropertyId;
+    QualType PropType = Context.getCanonicalType(property->getType());
     // Check that this is a previously declared 'ivar' in 'IDecl' interface
     Ivar = IDecl->lookupInstanceVariable(PropertyIvar);
     if (!Ivar) {
-      if (getLangOptions().ObjCNonFragileABI)
-        Diag(PropertyLoc, diag::error_synthesized_ivar_yet_not_supported) 
-                          << PropertyId;
-      else
+      if (getLangOptions().ObjCNonFragileABI) {
+        Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc, 
+                                    PropertyIvar, PropType, 
+                                    ObjCIvarDecl::Private,
+                                    (Expr *)0);
+        property->setPropertyIvarDecl(Ivar);
+      }
+      else {
         Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
-      return DeclPtrTy();
+        return DeclPtrTy();
+      }
     }
-    QualType PropType = Context.getCanonicalType(property->getType());
     QualType IvarType = Context.getCanonicalType(Ivar->getType());
     
     // Check that type of property and its ivar are type compatible.
index 31d415e2ace917c6897ebda157fee1cbde3c6d56..e2de77d3a28c238871ce48c7aa3ed5d1f49b93df 100644 (file)
@@ -16,7 +16,6 @@ typedef signed char BOOL;
 @end
 
 @implementation XCDeviceWillExecuteInfoBaton
-  // Produce an error when compiling for -arch x86_64 (or "non-fragile" ABI)
-  @synthesize sdkPath; // expected-error{{instance variable synthesis not yet supported (need to declare 'sdkPath' explicitly)}}
+  @synthesize sdkPath; 
 @end
 
diff --git a/test/SemaObjC/synthesized-ivar.m b/test/SemaObjC/synthesized-ivar.m
new file mode 100644 (file)
index 0000000..de44857
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fsyntax-only -triple x86_64-apple-darwin9 -verify %s
+@interface I
+{
+}
+@property int IP;
+@end
+
+@implementation I
+@synthesize IP;
+- (int) Meth {
+   return IP;
+}
+@end