[cfe-commits] r42971 - in /cfe/trunk: AST/Decl.cpp AST/Type.cpp Sema/SemaExpr.cpp include/clang/AST/Type.h

Steve Naroff snaroff at apple.com
Sun Oct 14 16:13:52 PDT 2007


Author: snaroff
Date: Sun Oct 14 18:13:51 2007
New Revision: 42971

URL: http://llvm.org/viewvc/llvm-project?rev=42971&view=rev
Log:

- Teach ObjcInterfaceDecl::lookupInstance/ClassMethod to look through protocols.
- Start looking up methods in the global method pools (for "id").
- Start integrating interface types into the type system.


Modified:
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/AST/Type.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=42971&r1=42970&r2=42971&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Sun Oct 14 18:13:51 2007
@@ -422,8 +422,20 @@
         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 @@
         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();

Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=42971&r1=42970&r2=42971&view=diff

==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Sun Oct 14 18:13:51 2007
@@ -267,6 +267,10 @@
   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 @@
       return tagTypesAreCompatible(lcanon, rcanon);
     case Type::Builtin:
       return builtinTypesAreCompatible(lcanon, rcanon); 
+    case Type::ObjcInterface:
+      return interfaceTypesAreCompatible(lcanon, rcanon); 
     default:
       assert(0 && "unexpected type");
   }

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=42971&r1=42970&r2=42971&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sun Oct 14 18:13:51 2007
@@ -1905,7 +1905,10 @@
   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 @@
     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();
   }

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Oct 14 18:13:51 2007
@@ -324,6 +324,7 @@
   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;





More information about the cfe-commits mailing list