[cfe-commits] r60792 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/CodeGen/CGObjC.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDeclObjC.cpp test/CodeGenObjC/newproperty-nested-synthesis-1.m

Fariborz Jahanian fjahanian at apple.com
Tue Dec 9 12:23:05 PST 2008


Author: fjahanian
Date: Tue Dec  9 14:23:04 2008
New Revision: 60792

URL: http://llvm.org/viewvc/llvm-project?rev=60792&view=rev
Log:
Support for implementation of property in the case where
the synthesis is in an implementation of s subclass of
a super class where the property has been declared.


Added:
    cfe/trunk/test/CodeGenObjC/newproperty-nested-synthesis-1.m
Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Dec  9 14:23:04 2008
@@ -216,7 +216,7 @@
   /// implict parameters. This must be called prior to using getSelfDecl()
   /// or getCmdDecl(). The call is ignored if the implicit paramters
   /// have already been created.
-  void createImplicitParams(ASTContext &Context);
+  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
 
   ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
   ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=60792&r1=60791&r2=60792&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Dec  9 14:23:04 2008
@@ -220,13 +220,14 @@
 // Objective-C Decl Implementation
 //===----------------------------------------------------------------------===//
 
-void ObjCMethodDecl::createImplicitParams(ASTContext &Context) {
+void ObjCMethodDecl::createImplicitParams(ASTContext &Context, 
+                                          const ObjCInterfaceDecl *OID) {
   QualType selfTy;
   if (isInstance()) {
     // There may be no interface context due to error in declaration
     // of the interface (which has been reported). Recover gracefully.
-    if (ObjCInterfaceDecl *OID = getClassInterface()) {
-      selfTy = Context.getObjCInterfaceType(OID);
+    if (OID) {
+      selfTy = Context.getObjCInterfaceType(const_cast<ObjCInterfaceDecl *>(OID));
       selfTy = Context.getPointerType(selfTy);
     } else {
       selfTy = Context.getObjCIdType();

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=60792&r1=60791&r2=60792&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Dec  9 14:23:04 2008
@@ -137,14 +137,15 @@
 /// GenerateObjCGetter - Generate an Objective-C property getter
 /// function. The given Decl must be either an ObjCCategoryImplDecl
 /// or an ObjCImplementationDecl.
-void CodeGenFunction::GenerateObjCGetter(const ObjCPropertyImplDecl *PID) {
+void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP,
+                                         const ObjCPropertyImplDecl *PID) {
   ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl();
   const ObjCPropertyDecl *PD = PID->getPropertyDecl();
   ObjCMethodDecl *OMD = PD->getGetterMethodDecl();
   assert(OMD && "Invalid call to generate getter (empty method)");
   // FIXME: This is rather murky, we create this here since they will
   // not have been created by Sema for us.
-  OMD->createImplicitParams(getContext());
+  OMD->createImplicitParams(getContext(), IMP->getClassInterface());
   StartObjCMethod(OMD);
 
   // Determine if we should use an objc_getProperty call for
@@ -173,7 +174,7 @@
     QualType IdTy = getContext().getObjCIdType();
     llvm::Value *SelfAsId = 
       Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy));
-    llvm::Value *Offset = EmitIvarOffset(OMD->getClassInterface(), Ivar);
+    llvm::Value *Offset = EmitIvarOffset(IMP->getClassInterface(), Ivar);
     llvm::Value *True =
       llvm::ConstantInt::get(Types.ConvertTypeForMem(getContext().BoolTy), 1);
     CallArgList Args;
@@ -204,14 +205,15 @@
 /// GenerateObjCSetter - Generate an Objective-C property setter
 /// function. The given Decl must be either an ObjCCategoryImplDecl
 /// or an ObjCImplementationDecl.
-void CodeGenFunction::GenerateObjCSetter(const ObjCPropertyImplDecl *PID) {
+void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
+                                         const ObjCPropertyImplDecl *PID) {
   ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl();
   const ObjCPropertyDecl *PD = PID->getPropertyDecl();
   ObjCMethodDecl *OMD = PD->getSetterMethodDecl();
   assert(OMD && "Invalid call to generate setter (empty method)");
   // FIXME: This is rather murky, we create this here since they will
   // not have been created by Sema for us.  
-  OMD->createImplicitParams(getContext());
+  OMD->createImplicitParams(getContext(), IMP->getClassInterface());
   StartObjCMethod(OMD);
 
   bool IsCopy = PD->getSetterKind() == ObjCPropertyDecl::Copy;
@@ -244,7 +246,7 @@
     QualType IdTy = getContext().getObjCIdType();
     llvm::Value *SelfAsId = 
       Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy));
-    llvm::Value *Offset = EmitIvarOffset(OMD->getClassInterface(), Ivar);
+    llvm::Value *Offset = EmitIvarOffset(IMP->getClassInterface(), Ivar);
     llvm::Value *Arg = LocalDeclMap[OMD->getParamDecl(0)];
     llvm::Value *ArgAsId = 
       Builder.CreateBitCast(Builder.CreateLoad(Arg, "arg"),

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=60792&r1=60791&r2=60792&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Dec  9 14:23:04 2008
@@ -45,6 +45,7 @@
   class ObjCInterfaceDecl;
   class ObjCIvarDecl;
   class ObjCMethodDecl;
+  class ObjCImplementationDecl;
   class ObjCPropertyImplDecl;
   class TargetInfo;
   class VarDecl;
@@ -176,11 +177,13 @@
 
   /// GenerateObjCGetter - Synthesize an Objective-C property getter
   /// function.
-  void GenerateObjCGetter(const ObjCPropertyImplDecl *PID);
+  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
+                          const ObjCPropertyImplDecl *PID);
 
   /// GenerateObjCSetter - Synthesize an Objective-C property setter
   /// function for the given property.
-  void GenerateObjCSetter(const ObjCPropertyImplDecl *PID);
+  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
+                          const ObjCPropertyImplDecl *PID);
 
   void GenerateCode(const FunctionDecl *FD,
                     llvm::Function *Fn);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=60792&r1=60791&r2=60792&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Dec  9 14:23:04 2008
@@ -980,10 +980,12 @@
       // property. What we want to know is if the method is defined in
       // this implementation.
       if (!D->getInstanceMethod(PD->getGetterName()))
-        CodeGenFunction(*this).GenerateObjCGetter(PID);
+        CodeGenFunction(*this).GenerateObjCGetter(
+                                 const_cast<ObjCImplementationDecl *>(D), PID);
       if (!PD->isReadOnly() &&
           !D->getInstanceMethod(PD->getSetterName()))
-        CodeGenFunction(*this).GenerateObjCSetter(PID);
+        CodeGenFunction(*this).GenerateObjCSetter(
+                                 const_cast<ObjCImplementationDecl *>(D), PID);
     }
   }
 }

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=60792&r1=60791&r2=60792&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Dec  9 14:23:04 2008
@@ -42,7 +42,7 @@
   // binding to their use.
 
   // Insert the invisible arguments, self and _cmd!
-  MDecl->createImplicitParams(Context);
+  MDecl->createImplicitParams(Context, MDecl->getClassInterface());
   
   PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope);
   PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);

Added: cfe/trunk/test/CodeGenObjC/newproperty-nested-synthesis-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/newproperty-nested-synthesis-1.m?rev=60792&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/newproperty-nested-synthesis-1.m (added)
+++ cfe/trunk/test/CodeGenObjC/newproperty-nested-synthesis-1.m Tue Dec  9 14:23:04 2008
@@ -0,0 +1,78 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s
+
+ at interface Object
+- (id) new;
+ at end
+
+ at interface Tester : Object
+ at property char PropertyAtomic_char;
+ at property short PropertyAtomic_short;
+ at property int PropertyAtomic_int;
+ at property long PropertyAtomic_long;
+ at property long long PropertyAtomic_longlong;
+ at property float PropertyAtomic_float;
+ at property double PropertyAtomic_double;
+ at property(assign) id PropertyAtomic_id;
+ at property(retain) id PropertyAtomicRetained_id;
+ at property(copy) id PropertyAtomicRetainedCopied_id;
+ at property(retain) id PropertyAtomicRetainedGCOnly_id;
+ at property(copy) id PropertyAtomicRetainedCopiedGCOnly_id;
+ at end
+
+ at implementation Tester
+ at dynamic PropertyAtomic_char;
+ at dynamic PropertyAtomic_short;
+ at dynamic PropertyAtomic_int;
+ at dynamic PropertyAtomic_long;
+ at dynamic PropertyAtomic_longlong;
+ at dynamic PropertyAtomic_float;
+ at dynamic PropertyAtomic_double;
+ at dynamic PropertyAtomic_id;
+ at dynamic PropertyAtomicRetained_id;
+ at dynamic PropertyAtomicRetainedCopied_id;
+ at dynamic PropertyAtomicRetainedGCOnly_id;
+ at dynamic PropertyAtomicRetainedCopiedGCOnly_id;
+ at end
+
+ at interface SubClass : Tester
+{
+    char PropertyAtomic_char;
+    short PropertyAtomic_short;
+    int PropertyAtomic_int;
+    long PropertyAtomic_long;
+    long long PropertyAtomic_longlong;
+    float PropertyAtomic_float;
+    double PropertyAtomic_double;
+    id PropertyAtomic_id;
+    id PropertyAtomicRetained_id;
+    id PropertyAtomicRetainedCopied_id;
+    id PropertyAtomicRetainedGCOnly_id;
+    id PropertyAtomicRetainedCopiedGCOnly_id;
+}
+ at end
+
+ at implementation SubClass
+ at synthesize PropertyAtomic_char;
+ at synthesize PropertyAtomic_short;
+ at synthesize PropertyAtomic_int;
+ at synthesize PropertyAtomic_long;
+ at synthesize PropertyAtomic_longlong;
+ at synthesize PropertyAtomic_float;
+ at synthesize PropertyAtomic_double;
+ at synthesize PropertyAtomic_id;
+ at synthesize PropertyAtomicRetained_id;
+ at synthesize PropertyAtomicRetainedCopied_id;
+ at synthesize PropertyAtomicRetainedGCOnly_id;
+ at synthesize PropertyAtomicRetainedCopiedGCOnly_id;
+ at end
+
+int main()
+{
+    SubClass *f = [SubClass new];
+    f.PropertyAtomic_int = 1;
+
+    f.PropertyAtomic_int += 3;
+
+    f.PropertyAtomic_int -= 4;
+    return f.PropertyAtomic_int;
+}





More information about the cfe-commits mailing list