]> granicus.if.org Git - clang/commitdiff
- Teach ObjcInterfaceDecl::lookupInstance/ClassMethod to look through protocols.
authorSteve Naroff <snaroff@apple.com>
Sun, 14 Oct 2007 23:13:51 +0000 (23:13 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 14 Oct 2007 23:13:51 +0000 (23:13 +0000)
- Start looking up methods in the global method pools (for "id").
- Start integrating interface types into the type system.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42971 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Decl.cpp
AST/Type.cpp
Sema/SemaExpr.cpp
include/clang/AST/Type.h

index 908bab4277334db5095797ab35df4e545f4146a2..30ca5e6e1ba2549e1297a3bfab9161e83860762c 100644 (file)
@@ -422,8 +422,20 @@ ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) {
         return methods[i];
       }
     }
+    // Didn't find one yet - look through protocols.
+    ObjcProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
+    int numProtocols = ClassDecl->getNumIntfRefProtocols();
+    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
+      ObjcMethodDecl **methods = protocols[pIdx]->getInstanceMethods();
+      int methodCount = protocols[pIdx]->getNumInstanceMethods();
+      for (int i = 0; i < methodCount; ++i) {
+        if (methods[i]->getSelector() == Sel) {
+          return methods[i];
+        }
+      }
+    }
     // Didn't find one yet - now look through categories.
-    ObjcCategoryDecl *CatDecl = this->getCategoryList();
+    ObjcCategoryDecl *CatDecl = ClassDecl->getCategoryList();
     while (CatDecl) {
       ObjcMethodDecl **methods = CatDecl->getInstanceMethods();
       int methodCount = CatDecl->getNumInstanceMethods();
@@ -451,8 +463,20 @@ ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector &Sel) {
         return methods[i];
       }
     }
+    // Didn't find one yet - look through protocols.
+    ObjcProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
+    int numProtocols = ClassDecl->getNumIntfRefProtocols();
+    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
+      ObjcMethodDecl **methods = protocols[pIdx]->getClassMethods();
+      int methodCount = protocols[pIdx]->getNumClassMethods();
+      for (int i = 0; i < methodCount; ++i) {
+        if (methods[i]->getSelector() == Sel) {
+          return methods[i];
+        }
+      }
+    }
     // Didn't find one yet - now look through categories.
-    ObjcCategoryDecl *CatDecl = this->getCategoryList();
+    ObjcCategoryDecl *CatDecl = ClassDecl->getCategoryList();
     while (CatDecl) {
       ObjcMethodDecl **methods = CatDecl->getClassMethods();
       int methodCount = CatDecl->getNumClassMethods();
index af07d7a1be8c89a33b8957dd17c504664da974ed..762bc66926f64cf2b764e92ab76dde425174f7d9 100644 (file)
@@ -267,6 +267,10 @@ bool Type::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
   return lBuiltin->getKind() == rBuiltin->getKind();
 }
 
+bool Type::interfaceTypesAreCompatible(QualType lhs, QualType rhs) {
+  return true; // FIXME: IMPLEMENT.
+}
+
 // C99 6.2.7p1: If both are complete types, then the following additional
 // requirements apply...FIXME (handle compatibility across source files).
 bool Type::tagTypesAreCompatible(QualType lhs, QualType rhs) {
@@ -398,6 +402,8 @@ bool Type::typesAreCompatible(QualType lhs, QualType rhs) {
       return tagTypesAreCompatible(lcanon, rcanon);
     case Type::Builtin:
       return builtinTypesAreCompatible(lcanon, rcanon); 
+    case Type::ObjcInterface:
+      return interfaceTypesAreCompatible(lcanon, rcanon); 
     default:
       assert(0 && "unexpected type");
   }
index 54e67141f20179cba742de0dac71dad2e70bc937..904230f82c2868d8634504e66db0f91fdd822572 100644 (file)
@@ -1905,7 +1905,10 @@ Sema::ExprResult Sema::ActOnInstanceMessage(
   QualType returnType;
   
   if (receiverType == GetObjcIdType()) {
-    returnType = Context.IntTy; // FIXME:just a placeholder
+    ObjcMethodDecl *Method = InstanceMethodPool[Sel].Method;
+    // FIXME: emit a diagnostic. For now, I want a hard error...
+    assert(Method && "missing method declaration");
+    returnType = Method->getMethodType();
   } else {
     // FIXME (snaroff): checking in this code from Patrick. Needs to be
     // revisited. how do we get the ClassDecl from the receiver expression?
@@ -1919,6 +1922,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(
     ObjcInterfaceDecl* ClassDecl = static_cast<ObjcInterfaceType*>(
                                      receiverType.getTypePtr())->getDecl();
     ObjcMethodDecl *Method = ClassDecl->lookupInstanceMethod(Sel);
+    // FIXME: emit a diagnostic. For now, I want a hard error...
     assert(Method && "missing method declaration");
     returnType = Method->getMethodType();
   }
index 061f34c054c217bf9ce8f0ecf08d4cf3c1f00cf8..696a14c40946f189e6b69a921cd7e111062fcfa6 100644 (file)
@@ -324,6 +324,7 @@ public:
   static bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
   static bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
   static bool builtinTypesAreCompatible(QualType, QualType);
+  static bool interfaceTypesAreCompatible(QualType, QualType);
 private:  
   QualType getCanonicalTypeInternal() const { return CanonicalType; }
   friend class QualType;