[cfe-commits] r43037 - in /cfe/trunk: Sema/SemaExpr.cpp include/clang/AST/ASTContext.h include/clang/Basic/DiagnosticKinds.def test/Sema/method-not-defined.m
Steve Naroff
snaroff at apple.com
Tue Oct 16 13:39:36 PDT 2007
Author: snaroff
Date: Tue Oct 16 15:39:36 2007
New Revision: 43037
URL: http://llvm.org/viewvc/llvm-project?rev=43037&view=rev
Log:
Emit diagnostics for methods not found.
Added:
cfe/trunk/test/Sema/method-not-defined.m
Modified:
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=43037&r1=43036&r2=43037&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Oct 16 15:39:36 2007
@@ -1930,11 +1930,17 @@
ObjcInterfaceDecl* ClassDecl = getObjCInterfaceDecl(receiverName);
ObjcMethodDecl *Method = ClassDecl->lookupClassMethod(Sel);
- assert(Method && "missing method declaration");
- QualType retType = Method->getMethodType();
+ QualType returnType;
+ if (!Method) {
+ Diag(lbrac, diag::warn_method_not_found, std::string("+"), Sel.getName(),
+ SourceRange(lbrac, rbrac));
+ returnType = GetObjcIdType();
+ } else {
+ returnType = Method->getMethodType();
+ }
// Expr *RExpr = global reference to the class symbol...
Expr **ArgExprs = reinterpret_cast<Expr **>(Args);
- return new ObjCMessageExpr(receiverName, Sel, retType, lbrac, rbrac,
+ return new ObjCMessageExpr(receiverName, Sel, returnType, lbrac, rbrac,
ArgExprs);
}
@@ -1953,9 +1959,13 @@
if (receiverType == GetObjcIdType()) {
ObjcMethodDecl *Method = InstanceMethodPool[Sel].Method;
- // FIXME: emit a diagnostic. For now, I want a hard error...
- assert(Method && "missing method declaration");
- returnType = Method->getMethodType();
+ if (!Method) {
+ Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
+ SourceRange(lbrac, rbrac));
+ returnType = GetObjcIdType();
+ } else {
+ 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?
@@ -1968,10 +1978,17 @@
"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...
ObjcMethodDecl *Method = ClassDecl->lookupInstanceMethod(Sel);
- // FIXME: emit a diagnostic. For now, I want a hard error...
- assert(Method && "missing method declaration");
- returnType = Method->getMethodType();
+ if (!Method) {
+ Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
+ SourceRange(lbrac, rbrac));
+ returnType = GetObjcIdType();
+ } else {
+ returnType = Method->getMethodType();
+ }
}
Expr **ArgExprs = reinterpret_cast<Expr **>(Args);
return new ObjCMessageExpr(RExpr, Sel, returnType, lbrac, rbrac, ArgExprs);
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=43037&r1=43036&r2=43037&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Oct 16 15:39:36 2007
@@ -157,12 +157,14 @@
// CURRENTLY UNUSED (10/15/07). ObjCStringLiteral now uses the hook below.
QualType getCFConstantStringType();
- // This setter/getter represents the actual ObjC type for an NSConstantString.
+ // This setter/getter represents the ObjC type for an NSConstantString.
void setObjcConstantStringInterface(ObjcInterfaceDecl *Decl);
QualType getObjcConstantStringInterface() const {
return ObjcConstantStringType;
}
+ // This setter/getter repreents the ObjC 'id' type. It is setup lazily, by
+ // Sema.
void setObjcIdType(TypedefDecl *Decl);
QualType getObjcIdType() const { return ObjcIdType; }
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=43037&r1=43036&r2=43037&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Oct 16 15:39:36 2007
@@ -454,6 +454,8 @@
"conflicting types for alias %0'")
DIAG(err_statically_allocated_object, ERROR,
"statically allocated Objective-c object '%0'")
+DIAG(warn_method_not_found, WARNING,
+ "method '%0%1' not found (return type defaults to 'id')")
//===----------------------------------------------------------------------===//
// Semantic Analysis
Added: cfe/trunk/test/Sema/method-not-defined.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/method-not-defined.m?rev=43037&view=auto
==============================================================================
--- cfe/trunk/test/Sema/method-not-defined.m (added)
+++ cfe/trunk/test/Sema/method-not-defined.m Tue Oct 16 15:39:36 2007
@@ -0,0 +1,14 @@
+// RUN: clang -fsyntax-only -verify %s
+
+typedef struct objc_object *id;
+ at interface Foo
+ at end
+
+void test() {
+ Foo *fooObj;
+ id obj;
+
+ [[Foo alloc] init]; // expected-warning {{method '+alloc' not found (return type defaults to 'id')}} expected-warning {{method '-init' not found (return type defaults to 'id')}}
+ [fooObj notdefined]; // expected-warning {{method '-notdefined' not found (return type defaults to 'id')}}
+ [obj whatever:1 :2 :3]; // expected-warning {{method '-whatever:::' not found (return type defaults to 'id'))}}
+}
More information about the cfe-commits
mailing list