[cfe-commits] r45142 - in /cfe/trunk: Sema/SemaDeclObjC.cpp Sema/SemaExpr.cpp test/Sema/message.m
Steve Naroff
snaroff at apple.com
Mon Dec 17 17:30:32 PST 2007
Author: snaroff
Date: Mon Dec 17 19:30:32 2007
New Revision: 45142
URL: http://llvm.org/viewvc/llvm-project?rev=45142&view=rev
Log:
Improve how we find private method decls. This involved:
- Changed Sema::ObjcActOnStartOfMethodDef() to register the methods with the global pools.
- Changed Sema::ActOnInstanceMessage() to look in global pools (should be much less error prone).
- Added a test case to message.m (for lookup that was broken).
Misc changes while I was investigating this...
- Changed Sema::ActOnAtEnd() to call AddFactoryMethodToGlobalPool (this looked like a cut/paste error).
- Added a comment and tweaked another where I was using the first person.
Modified:
cfe/trunk/Sema/SemaDeclObjC.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/message.m
Modified: cfe/trunk/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDeclObjC.cpp?rev=45142&r1=45141&r2=45142&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/Sema/SemaDeclObjC.cpp Mon Dec 17 19:30:32 2007
@@ -24,6 +24,12 @@
assert(CurFunctionDecl == 0 && "Method parsing confused");
ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
assert(MDecl != 0 && "Not a method declarator!");
+
+ // Allow the rest of sema to find private method decl implementations.
+ if (MDecl->isInstance())
+ AddInstanceMethodToGlobalPool(MDecl);
+ else
+ AddFactoryMethodToGlobalPool(MDecl);
// Allow all of Sema to see that we are entering a method definition.
CurMethodDecl = MDecl;
@@ -666,13 +672,15 @@
}
}
+// Note: For class/category implemenations, allMethods/allProperties is
+// always null.
void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
DeclTy **allMethods, unsigned allNum,
DeclTy **allProperties, unsigned pNum) {
Decl *ClassDecl = static_cast<Decl *>(classDecl);
- // FIXME: If we don't have a ClassDecl, we have an error. I (snaroff) would
- // prefer we always pass in a decl. If the decl has an error, isInvalidDecl()
+ // FIXME: If we don't have a ClassDecl, we have an error. We should consider
+ // always passing in a decl. If the decl has an error, isInvalidDecl()
// should be true.
if (!ClassDecl)
return;
@@ -731,8 +739,8 @@
} else {
clsMethods.push_back(Method);
ClsMap[Method->getSelector()] = Method;
- /// The following allows us to typecheck messages to "id".
- AddInstanceMethodToGlobalPool(Method);
+ /// The following allows us to typecheck messages to "Class".
+ AddFactoryMethodToGlobalPool(Method);
}
}
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=45142&r1=45141&r2=45142&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Dec 17 19:30:32 2007
@@ -2264,23 +2264,8 @@
if (receiverType == Context.getObjcIdType() ||
receiverType == Context.getObjcClassType()) {
Method = InstanceMethodPool[Sel].Method;
- // If we didn't find an public method, look for a private one.
- if (!Method && CurMethodDecl) {
- NamedDecl *impCxt = CurMethodDecl->getMethodContext();
- if (ObjcImplementationDecl *IMD =
- dyn_cast<ObjcImplementationDecl>(impCxt)) {
- if (receiverType == Context.getObjcIdType())
- Method = IMD->lookupInstanceMethod(Sel);
- else
- Method = IMD->lookupClassMethod(Sel);
- } else if (ObjcCategoryImplDecl *CID =
- dyn_cast<ObjcCategoryImplDecl>(impCxt)) {
- if (receiverType == Context.getObjcIdType())
- Method = CID->lookupInstanceMethod(Sel);
- else
- Method = CID->lookupClassMethod(Sel);
- }
- }
+ if (!Method)
+ Method = FactoryMethodPool[Sel].Method;
if (!Method) {
Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
SourceRange(lbrac, rbrac));
Modified: cfe/trunk/test/Sema/message.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/message.m?rev=45142&r1=45141&r2=45142&view=diff
==============================================================================
--- cfe/trunk/test/Sema/message.m (original)
+++ cfe/trunk/test/Sema/message.m Mon Dec 17 19:30:32 2007
@@ -36,3 +36,28 @@
// behavior isn't very desirable, however wee need it for GCC compatibility.
NSRect r = [obj rect];
}
+
+ at interface NSObject @end
+
+extern Class NSClassFromObject(id object);
+
+ at interface XX : NSObject
+ at end
+
+ at implementation XX
+
++ _privateMethod {
+ return self;
+}
+
+- (void) xx {
+ [NSClassFromObject(self) _privateMethod];
+}
+ at end
+
+ at implementation XX (Private)
+- (void) yy {
+ [NSClassFromObject(self) _privateMethod];
+}
+ at end
+
More information about the cfe-commits
mailing list