[cfe-commits] r50818 - in /cfe/trunk: Driver/ASTConsumers.cpp include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Parse/ParseObjc.cpp lib/Sema/SemaDeclObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Wed May 7 10:43:59 PDT 2008


Author: fjahanian
Date: Wed May  7 12:43:59 2008
New Revision: 50818

URL: http://llvm.org/viewvc/llvm-project?rev=50818&view=rev
Log:
This patch introduces declaration of getter methods for ObjC2's
properties. Couple of property tests will fail with this patch.
Will fix them next.


Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Parse/ParseObjc.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=50818&r1=50817&r2=50818&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed May  7 12:43:59 2008
@@ -273,16 +273,16 @@
   for (ObjCInterfaceDecl::classprop_iterator I = OID->classprop_begin(),
        E = OID->classprop_end(); I != E; ++I)
     PrintObjCPropertyDecl(*I);
-  
+  bool eol_needed = false;
   for (ObjCInterfaceDecl::classmeth_iterator I = OID->classmeth_begin(),
        E = OID->classmeth_end(); I != E; ++I)
-    PrintObjCMethodDecl(*I);
+    eol_needed = true, PrintObjCMethodDecl(*I);
   
   for (ObjCInterfaceDecl::instmeth_iterator I = OID->instmeth_begin(),
        E = OID->instmeth_end(); I != E; ++I)
-    PrintObjCMethodDecl(*I);
+    eol_needed = true, PrintObjCMethodDecl(*I);
   
-  Out << "@end\n";
+  Out << (eol_needed ? "\n at end\n" : "@end\n");
   // FIXME: implement the rest...
 }
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Wed May  7 12:43:59 2008
@@ -322,6 +322,10 @@
   
   void mergeProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
   
+  void addPropertyMethods(ASTContext &Context,
+                          ObjCPropertyDecl* Property,
+                          llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods);
+  
   typedef ObjCPropertyDecl * const * classprop_iterator;
   classprop_iterator classprop_begin() const { return PropertyDecl; }
   classprop_iterator classprop_end() const {
@@ -1078,10 +1082,15 @@
   Selector GetterName;    // getter name of NULL if no getter
   Selector SetterName;    // setter name of NULL if no setter
   
+  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
+  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
+
   ObjCPropertyDecl(SourceLocation L, IdentifierInfo *Id, QualType T)
     : NamedDecl(ObjCProperty, L, Id), DeclType(T),
-      PropertyAttributes(OBJC_PR_noattr), GetterName(Selector()), 
-      SetterName(Selector()) {}
+      PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
+      GetterName(Selector()), 
+      SetterName(Selector()),
+      GetterMethodDecl(0), SetterMethodDecl(0) {}
 public:
   static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L, 
                                   IdentifierInfo *Id, QualType T,
@@ -1102,6 +1111,12 @@
   Selector getSetterName() const { return SetterName; }
   void setSetterName(Selector Sel) { SetterName = Sel; }
   
+  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
+  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
+
+  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
+  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
+  
   // Related to @optional/@required declared in @protocol
   void setPropertyImplementation(PropertyControl pc) {
     PropertyImplementation = pc;

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Wed May  7 12:43:59 2008
@@ -270,6 +270,36 @@
   }
 }
 
+/// addPropertyMethods - Goes through list of properties declared in this class
+/// and builds setter/getter method declartions depending on the setter/getter
+/// attributes of the property.
+///
+void ObjCInterfaceDecl::addPropertyMethods(
+       ASTContext &Context,
+       ObjCPropertyDecl *property,
+       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 {
+    // 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, 0,
+                           true, false, ObjCMethodDecl::Required);
+    property->setGetterMethodDecl(ObjCMethod);
+    insMethods.push_back(ObjCMethod);
+  }
+}
+
 /// addProperties - Insert property declaration AST nodes into
 /// ObjCProtocolDecl's PropertyDecl field.
 ///

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed May  7 12:43:59 2008
@@ -271,9 +271,14 @@
           FieldDeclarator &FD = FieldDeclarators[i];
           // Install the property declarator into interfaceDecl.
           Selector GetterSel = 
-            PP.getSelectorTable().getNullarySelector(OCDS.getGetterName());
+          PP.getSelectorTable().getNullarySelector(OCDS.getGetterName() 
+                                                   ? OCDS.getGetterName() 
+                                                   : FD.D.getIdentifier());
           Selector SetterSel = 
-          PP.getSelectorTable().getNullarySelector(OCDS.getSetterName());
+          PP.getSelectorTable().getNullarySelector(OCDS.getSetterName()
+                                                   ? OCDS.getSetterName()
+                                                   // FIXME. This is not right!
+                                                   : FD.D.getIdentifier());
           DeclTy *Property = Actions.ActOnProperty(CurScope,
                                DS.getSourceRange().getBegin(), FD, OCDS,
                                GetterSel, SetterSel,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed May  7 12:43:59 2008
@@ -872,12 +872,17 @@
   }
   
   if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
-    I->addMethods(&insMethods[0], insMethods.size(),
-                  &clsMethods[0], clsMethods.size(), AtEndLoc);
     // Compares properties declaraed in this class to those of its 
     // super class.
     ComparePropertiesInBaseAndSuper(I);
     MergeProtocolPropertiesIntoClass(I, I);
+    for (ObjCInterfaceDecl::classprop_iterator P = I->classprop_begin(),
+         E = I->classprop_end(); P != E; ++P) {
+      I->addPropertyMethods(Context, *P, insMethods);
+    }
+    I->addMethods(&insMethods[0], insMethods.size(),
+                  &clsMethods[0], clsMethods.size(), AtEndLoc);
+    
   } else if (ObjCProtocolDecl *P = dyn_cast<ObjCProtocolDecl>(ClassDecl)) {
     P->addMethods(&insMethods[0], insMethods.size(),
                   &clsMethods[0], clsMethods.size(), AtEndLoc);
@@ -1029,19 +1034,19 @@
   QualType T = GetTypeForDeclarator(FD.D, S);
   ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, 
                                                      FD.D.getIdentifier(), T);
+  // Regardless of setter/getter attribute, we save the default getter/setter
+  // selector names in anticipation of declaration of setter/getter methods.
+  PDecl->setGetterName(GetterSel);
+  PDecl->setSetterName(SetterSel);
   
   if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
   
-  if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_getter) {
+  if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_getter)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
-    PDecl->setGetterName(GetterSel);
-  }
   
-  if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_setter) {
+  if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_setter)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
-    PDecl->setSetterName(SetterSel);
-  }
   
   if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_assign)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);





More information about the cfe-commits mailing list