This commit is only 95% of the bug fix. The last piece to this puzzle is to add the method decls to the implementation incrementally (as we encounter them). At the moment, the methods aren't added until we see an @end (which is too late).
I will complete this later...
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43989
91177308-0d34-0410-b5e6-
96231b3b80d8
return NULL;
}
+// lookupInstanceMethod - This method returns an instance method by looking in
+// the class implementation. Unlike interfaces, we don't look outside the
+// implementation.
+ObjcMethodDecl *ObjcImplementationDecl::lookupInstanceMethod(Selector &Sel) {
+ ObjcMethodDecl **methods = getInstanceMethods();
+ int methodCount = getNumInstanceMethods();
+ for (int i = 0; i < methodCount; ++i) {
+ if (methods[i]->getSelector() == Sel) {
+ return methods[i];
+ }
+ }
+ return NULL;
+}
+
+// lookupClassMethod - This method returns an instance method by looking in
+// the class implementation. Unlike interfaces, we don't look outside the
+// implementation.
+ObjcMethodDecl *ObjcImplementationDecl::lookupClassMethod(Selector &Sel) {
+ ObjcMethodDecl **methods = getClassMethods();
+ int methodCount = getNumClassMethods();
+ for (int i = 0; i < methodCount; ++i) {
+ if (methods[i]->getSelector() == Sel) {
+ return methods[i];
+ }
+ }
+ return NULL;
+}
/// ObjcImplementations - Keep track of all of the classes with
/// @implementation's, so that we can emit errors on duplicates.
- llvm::SmallPtrSet<IdentifierInfo*, 8> ObjcImplementations;
+ llvm::DenseMap<IdentifierInfo*, ObjcImplementationDecl*> ObjcImplementations;
/// ObjcProtocols - Keep track of all protocol declarations declared
/// with @protocol keyword, so that we can emit errors on duplicates and
new ObjcImplementationDecl(AtClassImplLoc, ClassName, IDecl, SDecl);
// Check that there is no duplicate implementation of this class.
- if (!ObjcImplementations.insert(ClassName))
+ if (ObjcImplementations[ClassName])
Diag(ClassLoc, diag::err_dup_implementation_class, ClassName->getName());
-
+ else // add it to the list.
+ ObjcImplementations[ClassName] = IMPDecl;
return IMPDecl;
}
// 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 =
+ ObjcImplementations[ClassDecl->getIdentifier()])
+ Method = ImpDecl->lookupInstanceMethod(Sel);
+ }
if (!Method) {
Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
SourceRange(lbrac, rbrac));
ObjcMethodDecl **getClassMethods() const { return ClassMethods; }
int getNumClassMethods() const { return NumClassMethods; }
+
+ ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
+ ObjcMethodDecl *lookupClassMethod(Selector &Sel);
ObjcIvarDecl **getImplDeclIVars() const { return Ivars; }
int getImplDeclNumIvars() const { return NumIvars; }
--- /dev/null
+// RUN: clang -fsyntax-only -verify %s
+
+@interface foo
+- (void)meth;
+@end
+
+@implementation foo
+- (void) contents {} // No declaration in @interface!
+- (void) meth { [self contents]; } // expected-warning {{method '-contents' not found (return type defaults to 'id')}}
+@end
+