[cfe-commits] r49306 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/ASTContext.cpp

Chris Lattner sabre at nondot.org
Sun Apr 6 21:13:03 PDT 2008


Author: lattner
Date: Sun Apr  6 23:13:03 2008
New Revision: 49306

URL: http://llvm.org/viewvc/llvm-project?rev=49306&view=rev
Log:
This predicate is just a generic "issuperclass" predicate, move it to the
ObjCInterfaceType as a method.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/ASTContext.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Apr  6 23:13:03 2008
@@ -315,13 +315,26 @@
   
   ObjCCategoryDecl* getCategoryList() const { return CategoryList; }
   void setCategoryList(ObjCCategoryDecl *category) { 
-         CategoryList = category; 
+    CategoryList = category;
   }
+  
+  /// isSuperClassOf - Return true if this class is the specified class or is a
+  /// super class of the specified interface class.
+  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
+    // If RHS is derived from LHS it is OK; else it is not OK.
+    while (I != NULL) {
+      if (this == I)
+        return true;
+      I = I->getSuperClass();
+    }
+    return false;
+  }
+  
   ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *ivarName,
                                        ObjCInterfaceDecl *&clsDeclared);
                                                                            
   // Get the local instance method declared in this interface.
-  ObjCMethodDecl *getInstanceMethod(Selector &Sel) {
+  ObjCMethodDecl *getInstanceMethod(Selector Sel) {
     for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); 
          I != E; ++I) {
       if ((*I)->getSelector() == Sel)
@@ -330,7 +343,7 @@
     return 0;
   }
   // Get the local class method declared in this interface.
-  ObjCMethodDecl *getClassMethod(Selector &Sel) {
+  ObjCMethodDecl *getClassMethod(Selector Sel) {
     for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); 
          I != E; ++I) {
       if ((*I)->getSelector() == Sel)

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Apr  6 23:13:03 2008
@@ -1443,20 +1443,6 @@
   return false;
 }
 
-/// isCompatibleInterfaceAssign - Return true if it is ok to assign a
-/// pointer from the RHS interface to the LHS interface.  This is true if the
-/// RHS is exactly LHS or if it is a subclass of LHS.
-static bool isCompatibleInterfaceAssign(ObjCInterfaceDecl *LHS,
-                                        ObjCInterfaceDecl *RHS) {
-  // If RHS is derived from LHS it is OK; else it is not OK.
-  while (RHS != NULL) {
-    if (RHS == LHS)
-      return true;
-    RHS = RHS->getSuperClass();
-  }
-  return false;
-}
-
 bool ASTContext::QualifiedInterfaceTypesAreCompatible(QualType lhs, 
                                                       QualType rhs) {
   const ObjCQualifiedInterfaceType *lhsQI =
@@ -1465,7 +1451,9 @@
     rhs->getAsObjCQualifiedInterfaceType();
   assert(lhsQI && rhsQI && "QualifiedInterfaceTypesAreCompatible - bad type");
   
-  if (!isCompatibleInterfaceAssign(lhsQI->getDecl(), rhsQI->getDecl()))
+  // Verify that the base decls are compatible, the RHS must be a subclass of
+  // the LHS.
+  if (!lhsQI->getDecl()->isSuperClassOf(rhsQI->getDecl()))
     return false;
   
   // All protocols in lhs must have a presence in rhs.
@@ -1857,8 +1845,9 @@
   case Type::Builtin:
     return builtinTypesAreCompatible(LHS, RHS); 
   case Type::ObjCInterface:
-    return isCompatibleInterfaceAssign(cast<ObjCInterfaceType>(LHS)->getDecl(),
-                                       cast<ObjCInterfaceType>(RHS)->getDecl());
+    // The LHS must be a superclass of the RHS.
+    return cast<ObjCInterfaceType>(LHS)->getDecl()->isSuperClassOf(
+                                   cast<ObjCInterfaceType>(RHS)->getDecl());
   case Type::Vector:
   case Type::OCUVector:
     return vectorTypesAreCompatible(LHS, RHS);





More information about the cfe-commits mailing list