[cfe-commits] r44685 - in /cfe/trunk: AST/Decl.cpp Driver/RewriteTest.cpp Sema/SemaExpr.cpp include/clang/AST/DeclObjC.h
Fariborz Jahanian
fjahanian at apple.com
Fri Dec 7 13:21:21 PST 2007
Author: fjahanian
Date: Fri Dec 7 15:21:21 2007
New Revision: 44685
URL: http://llvm.org/viewvc/llvm-project?rev=44685&view=rev
Log:
Implemented when static typing is combined with protocols and use as receiver
type.
Modified:
cfe/trunk/AST/Decl.cpp
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/DeclObjC.h
Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Fri Dec 7 15:21:21 2007
@@ -543,3 +543,45 @@
}
return NULL;
}
+
+// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
+// it inherited.
+ObjcMethodDecl *ObjcProtocolDecl::lookupInstanceMethod(Selector &Sel) {
+ ObjcMethodDecl *const*methods = getInstanceMethods();
+ int methodCount = getNumInstanceMethods();
+ for (int i = 0; i < methodCount; ++i) {
+ if (methods[i]->getSelector() == Sel) {
+ return methods[i];
+ }
+ }
+ if (getNumReferencedProtocols() > 0) {
+ ObjcProtocolDecl **RefPDecl = getReferencedProtocols();
+
+ for (int i = 0; i < getNumReferencedProtocols(); i++) {
+ if (ObjcMethodDecl *Method = RefPDecl[i]->lookupInstanceMethod(Sel))
+ return Method;
+ }
+ }
+ return NULL;
+}
+
+// lookupInstanceMethod - Lookup a class method in the protocol and protocols
+// it inherited.
+ObjcMethodDecl *ObjcProtocolDecl::lookupClassMethod(Selector &Sel) {
+ ObjcMethodDecl *const*methods = getClassMethods();
+ int methodCount = getNumClassMethods();
+ for (int i = 0; i < methodCount; ++i) {
+ if (methods[i]->getSelector() == Sel) {
+ return methods[i];
+ }
+ }
+ if (getNumReferencedProtocols() > 0) {
+ ObjcProtocolDecl **RefPDecl = getReferencedProtocols();
+
+ for (int i = 0; i < getNumReferencedProtocols(); i++) {
+ if (ObjcMethodDecl *Method = RefPDecl[i]->lookupClassMethod(Sel))
+ return Method;
+ }
+ }
+ return NULL;
+}
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Fri Dec 7 15:21:21 2007
@@ -1446,6 +1446,10 @@
SourceLocation());
MsgExprs.push_back(Unop);
} else {
+ // Remove all type-casts because it may contain objc-style types; e.g.
+ // Foo<Proto> *.
+ while (CastExpr *CE = dyn_cast<CastExpr>(recExpr))
+ recExpr = CE->getSubExpr();
recExpr = new CastExpr(Context->getObjcIdType(), recExpr, SourceLocation());
MsgExprs.push_back(recExpr);
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Dec 7 15:21:21 2007
@@ -2232,14 +2232,32 @@
static_cast<PointerType*>(receiverType.getTypePtr());
receiverType = pointerType->getPointeeType();
}
- assert(ObjcInterfaceType::classof(receiverType.getTypePtr()) &&
- "bad receiver type");
- ObjcInterfaceDecl* ClassDecl = static_cast<ObjcInterfaceType*>(
- receiverType.getTypePtr())->getDecl();
- // FIXME: consider using InstanceMethodPool, since it will be faster
- // than the following method (which can do *many* linear searches). The
- // idea is to add class info to InstanceMethodPool...
- Method = ClassDecl->lookupInstanceMethod(Sel);
+ ObjcInterfaceDecl* ClassDecl;
+ if (ObjcQualifiedInterfaceType *QIT =
+ dyn_cast<ObjcQualifiedInterfaceType>(receiverType)) {
+ ObjcInterfaceType * OITypePtr = QIT->getInterfaceType();
+
+ ClassDecl = OITypePtr->getDecl();
+ Method = ClassDecl->lookupInstanceMethod(Sel);
+ if (!Method) {
+ // search protocols
+ for (unsigned i = 0; i < QIT->getNumProtocols(); i++) {
+ ObjcProtocolDecl *PDecl = QIT->getProtocols(i);
+ if (PDecl && (Method = PDecl->lookupInstanceMethod(Sel)))
+ break;
+ }
+ }
+ }
+ else {
+ assert(ObjcInterfaceType::classof(receiverType.getTypePtr()) &&
+ "bad receiver type");
+ ClassDecl = static_cast<ObjcInterfaceType*>(
+ receiverType.getTypePtr())->getDecl();
+ // FIXME: consider using InstanceMethodPool, since it will be faster
+ // than the following method (which can do *many* linear searches). The
+ // idea is to add class info to InstanceMethodPool...
+ Method = ClassDecl->lookupInstanceMethod(Sel);
+ }
if (!Method) {
// If we have an implementation in scope, check "private" methods.
if (ObjcImplementationDecl *ImpDecl =
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Dec 7 15:21:21 2007
@@ -283,6 +283,9 @@
ObjcMethodDecl** getClassMethods() const { return ClassMethods; }
int getNumClassMethods() const { return NumClassMethods; }
+ ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
+ ObjcMethodDecl *lookupClassMethod(Selector &Sel);
+
bool isForwardDecl() const { return isForwardProtoDecl; }
void setForwardDecl(bool val) { isForwardProtoDecl = val; }
More information about the cfe-commits
mailing list