[cfe-commits] r55352 - in /cfe/trunk/lib: AST/DeclObjC.cpp Parse/ParseObjc.cpp

Daniel Dunbar daniel at zuster.org
Mon Aug 25 19:32:47 PDT 2008


Author: ddunbar
Date: Mon Aug 25 21:32:45 2008
New Revision: 55352

URL: http://llvm.org/viewvc/llvm-project?rev=55352&view=rev
Log:
Synthesize property setter method as we do for getter.
 - Also, fix Parser to construct proper SetterName selector (should be
   lifted out of parser though).

Modified:
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Parse/ParseObjc.cpp

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Aug 25 21:32:45 2008
@@ -387,24 +387,48 @@
        llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods) {
   // Find the default getter and if one not found, add one.
   ObjCMethodDecl *GetterDecl = getInstanceMethod(property->getGetterName());
-  if (GetterDecl) {
-    // An instance method with same name as property getter name found.
-    property->setGetterMethodDecl(GetterDecl);
-  }
-  else {
+  if (!GetterDecl) {
     // No instance method of same name as property getter name was found.
     // Declare a getter method and add it to the list of methods 
     // for this class.
-    QualType resultDeclType = property->getType();
-    ObjCMethodDecl* ObjCMethod =
-    ObjCMethodDecl::Create(Context, property->getLocation(), 
-                           property->getLocation(), 
-                           property->getGetterName(), resultDeclType,
-                           this,
-                           true, false, true, ObjCMethodDecl::Required);
-    property->setGetterMethodDecl(ObjCMethod);
-    insMethods.push_back(ObjCMethod);
+    GetterDecl = 
+      ObjCMethodDecl::Create(Context, property->getLocation(), 
+                             property->getLocation(), 
+                             property->getGetterName(), 
+                             property->getType(),
+                             this,
+                             true, false, true, ObjCMethodDecl::Required);
+    insMethods.push_back(GetterDecl);
+  }
+  property->setGetterMethodDecl(GetterDecl);
+
+  // Find the default setter and if one not found, add one.
+  ObjCMethodDecl *SetterDecl = getInstanceMethod(property->getSetterName());
+  if (!SetterDecl) {
+    // No instance method of same name as property setter name was found.
+    // Declare a setter method and add it to the list of methods 
+    // for this class.
+    SetterDecl =
+      ObjCMethodDecl::Create(Context, property->getLocation(), 
+                             property->getLocation(), 
+                             property->getSetterName(), 
+                             property->getType(),
+                             this,
+                             true, false, true, ObjCMethodDecl::Required);
+    insMethods.push_back(SetterDecl);
+
+    // Invent the arguments for the setter. We don't bother making a
+    // nice name for the argument.
+    ParmVarDecl *Argument = ParmVarDecl::Create(Context, 
+                                               SetterDecl,
+                                               SourceLocation(), 
+                                               property->getIdentifier(),
+                                               property->getType(),
+                                               VarDecl::None,
+                                               0, 0);
+    SetterDecl->setMethodParams(&Argument, 1);
   }
+  property->setSetterMethodDecl(SetterDecl);
 }
 
 /// addProperties - Insert property declaration AST nodes into

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=55352&r1=55351&r2=55352&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Aug 25 21:32:45 2008
@@ -212,6 +212,23 @@
   return 0;
 }
 
+/// constructSetterName - Return the setter name for the given
+/// identifier, i.e. "set" + Name where the initial character of Name
+/// has been capitalized.
+static IdentifierInfo *constructSetterName(IdentifierTable &Idents,
+                                           const IdentifierInfo *Name) {
+  unsigned N = Name->getLength();
+  char *SelectorName = new char[3 + N];
+  memcpy(SelectorName, "set", 3);
+  memcpy(&SelectorName[3], Name->getName(), N);
+  SelectorName[3] = toupper(SelectorName[3]);
+
+  IdentifierInfo *Setter = 
+    &Idents.get(SelectorName, &SelectorName[3 + N]);
+  delete[] SelectorName;
+  return Setter;
+}
+
 ///   objc-interface-decl-list:
 ///     empty
 ///     objc-interface-decl-list objc-property-decl [OBJC2]
@@ -276,11 +293,12 @@
           PP.getSelectorTable().getNullarySelector(OCDS.getGetterName() 
                                                    ? OCDS.getGetterName() 
                                                    : FD.D.getIdentifier());
+          IdentifierInfo *SetterName = OCDS.getSetterName();
+          if (!SetterName)
+            SetterName = constructSetterName(PP.getIdentifierTable(),
+                                             FD.D.getIdentifier());
           Selector SetterSel = 
-          PP.getSelectorTable().getNullarySelector(OCDS.getSetterName()
-                                                   ? OCDS.getSetterName()
-                                                   // FIXME. This is not right!
-                                                   : FD.D.getIdentifier());
+            PP.getSelectorTable().getUnarySelector(SetterName);
           DeclTy *Property = Actions.ActOnProperty(CurScope,
                                AtLoc, FD, OCDS,
                                GetterSel, SetterSel,





More information about the cfe-commits mailing list