aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-10-14 23:13:51 +0000
committerSteve Naroff <snaroff@apple.com>2007-10-14 23:13:51 +0000
commitff1afdb4f5ee2fc74ec0af788e18b3a036eaaafe (patch)
treef82832eee6a41de64b37863fb3512f429b1ddc0e
parent3d58138992b9bc7b34aaa680f3ddf3971292eb7d (diff)
- 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42971 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/Decl.cpp28
-rw-r--r--AST/Type.cpp6
-rw-r--r--Sema/SemaExpr.cpp6
-rw-r--r--include/clang/AST/Type.h1
4 files changed, 38 insertions, 3 deletions
diff --git a/AST/Decl.cpp b/AST/Decl.cpp
index 908bab4277..30ca5e6e1b 100644
--- a/AST/Decl.cpp
+++ b/AST/Decl.cpp
@@ -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();
diff --git a/AST/Type.cpp b/AST/Type.cpp
index af07d7a1be..762bc66926 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -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");
}
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 54e67141f2..904230f82c 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -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();
}
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h
index 061f34c054..696a14c409 100644
--- a/include/clang/AST/Type.h
+++ b/include/clang/AST/Type.h
@@ -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;