[cfe-commits] r60386 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Mon Dec 1 16:19:13 PST 2008


Author: fjahanian
Date: Mon Dec  1 18:19:12 2008
New Revision: 60386

URL: http://llvm.org/viewvc/llvm-project?rev=60386&view=rev
Log:
This patch corrects problem in searching for a setter/getter method for
a property. Previous scheme of seaching in interface's list of methods
would not work because this list is not yet constructed. This is in preparation
for doing semantic check on viability of setter/getter method declarations.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.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=60386&r1=60385&r2=60386&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Dec  1 18:19:12 2008
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "llvm/ADT/DenseMap.h"
 
 namespace clang {
 class Expr;
@@ -385,7 +386,8 @@
   
   void addPropertyMethods(ASTContext &Context,
                           ObjCPropertyDecl* Property,
-                          llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods);
+                          llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods,
+                          llvm::DenseMap<Selector, const ObjCMethodDecl*> &InsMap);
   
   typedef ObjCPropertyDecl * const * classprop_iterator;
   classprop_iterator classprop_begin() const { return PropertyDecl; }
@@ -641,7 +643,8 @@
 
   void addPropertyMethods(ASTContext &Context,
                           ObjCPropertyDecl* Property,
-                          llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods);
+                          llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods,
+                          llvm::DenseMap<Selector, const ObjCMethodDecl*> &InsMap);
   
   typedef ObjCPropertyDecl * const * classprop_iterator;
   classprop_iterator classprop_begin() const { return PropertyDecl; }
@@ -882,7 +885,8 @@
 
   void addPropertyMethods(ASTContext &Context,
                           ObjCPropertyDecl* Property,
-                          llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods);
+                          llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods,
+                          llvm::DenseMap<Selector, const ObjCMethodDecl*> &InsMap);
   
   ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
   

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Dec  1 18:19:12 2008
@@ -426,24 +426,14 @@
 addPropertyMethods(Decl *D,
                    ASTContext &Context,
                    ObjCPropertyDecl *property,
-                   llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods) {
+                   llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods,
+                   llvm::DenseMap<Selector, const ObjCMethodDecl*> &InsMap) {
   ObjCMethodDecl *GetterDecl, *SetterDecl = 0;
-
-  if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) {
-    GetterDecl = OID->getInstanceMethod(property->getGetterName());
-    if (!property->isReadOnly())
-      SetterDecl = OID->getInstanceMethod(property->getSetterName());
-  } else if (ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(D)) {
-    GetterDecl = OCD->getInstanceMethod(property->getGetterName());
-    if (!property->isReadOnly())
-      SetterDecl = OCD->getInstanceMethod(property->getSetterName());
-  } else {
-    ObjCProtocolDecl *OPD = cast<ObjCProtocolDecl>(D);
-    GetterDecl = OPD->getInstanceMethod(property->getGetterName());
-    if (!property->isReadOnly())
-      SetterDecl = OPD->getInstanceMethod(property->getSetterName());
-  }
-
+  
+  GetterDecl = const_cast<ObjCMethodDecl*>(InsMap[property->getGetterName()]);
+  if (!property->isReadOnly())
+    SetterDecl = const_cast<ObjCMethodDecl*>(InsMap[property->getSetterName()]);
+  
   // FIXME: The synthesized property we set here is misleading. We
   // almost always synthesize these methods unless the user explicitly
   // provided prototypes (which is odd, but allowed). Sema should be
@@ -463,6 +453,7 @@
                              D,
                              true, false, true, ObjCMethodDecl::Required);
     insMethods.push_back(GetterDecl);
+    InsMap[property->getGetterName()] = GetterDecl;
   }
   property->setGetterMethodDecl(GetterDecl);
 
@@ -483,7 +474,7 @@
                              D,
                              true, false, true, ObjCMethodDecl::Required);
     insMethods.push_back(SetterDecl);
-
+    InsMap[property->getSetterName()] = SetterDecl;
     // Invent the arguments for the setter. We don't bother making a
     // nice name for the argument.
     ParmVarDecl *Argument = ParmVarDecl::Create(Context, 
@@ -505,8 +496,9 @@
 void ObjCInterfaceDecl::addPropertyMethods(
        ASTContext &Context,
        ObjCPropertyDecl *property,
-       llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods) {
-  ::addPropertyMethods(this, Context, property, insMethods);
+       llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods,
+       llvm::DenseMap<Selector, const ObjCMethodDecl*> &InsMap) {
+  ::addPropertyMethods(this, Context, property, insMethods, InsMap);
 }
 
 /// addPropertyMethods - Goes through list of properties declared in this class
@@ -516,8 +508,9 @@
 void ObjCCategoryDecl::addPropertyMethods(
        ASTContext &Context,
        ObjCPropertyDecl *property,
-       llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods) {
-  ::addPropertyMethods(this, Context, property, insMethods);
+       llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods, 
+       llvm::DenseMap<Selector, const ObjCMethodDecl*> &InsMap) {
+  ::addPropertyMethods(this, Context, property, insMethods, InsMap);
 }
 
 /// addPropertyMethods - Goes through list of properties declared in this class
@@ -527,8 +520,9 @@
 void ObjCProtocolDecl::addPropertyMethods(
        ASTContext &Context,
        ObjCPropertyDecl *property,
-       llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods) {
-  ::addPropertyMethods(this, Context, property, insMethods);
+       llvm::SmallVector<ObjCMethodDecl*, 32> &insMethods,
+       llvm::DenseMap<Selector, const ObjCMethodDecl*> &InsMap) {
+  ::addPropertyMethods(this, Context, property, insMethods, InsMap);
 }
 
 /// addProperties - Insert property declaration AST nodes into

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Dec  1 18:19:12 2008
@@ -941,14 +941,14 @@
     MergeProtocolPropertiesIntoClass(I, I);
     for (ObjCInterfaceDecl::classprop_iterator i = I->classprop_begin(),
            e = I->classprop_end(); i != e; ++i)
-      I->addPropertyMethods(Context, *i, insMethods);
+      I->addPropertyMethods(Context, *i, insMethods, InsMap);
     I->addMethods(&insMethods[0], insMethods.size(),
                   &clsMethods[0], clsMethods.size(), AtEndLoc);
     
   } else if (ObjCProtocolDecl *P = dyn_cast<ObjCProtocolDecl>(ClassDecl)) {
     for (ObjCProtocolDecl::classprop_iterator i = P->classprop_begin(),
            e = P->classprop_end(); i != e; ++i)
-      P->addPropertyMethods(Context, *i, insMethods);
+      P->addPropertyMethods(Context, *i, insMethods, InsMap);
     P->addMethods(&insMethods[0], insMethods.size(),
                   &clsMethods[0], clsMethods.size(), AtEndLoc);
   }
@@ -959,7 +959,7 @@
     // merge them into category as well?
     for (ObjCCategoryDecl::classprop_iterator i = C->classprop_begin(),
            e = C->classprop_end(); i != e; ++i)
-      C->addPropertyMethods(Context, *i, insMethods);
+      C->addPropertyMethods(Context, *i, insMethods, InsMap);
     C->addMethods(&insMethods[0], insMethods.size(),
                   &clsMethods[0], clsMethods.size(), AtEndLoc);
   }





More information about the cfe-commits mailing list