summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprObjC.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-04-14 20:04:41 +0000
committerDouglas Gregor <dgregor@apple.com>2010-04-14 20:04:41 +0000
commit280e1ee0ae44f161971539ad6ab965169b932ae9 (patch)
tree31621cbbc1e63f6bf5865974a5e6481e71c610eb /clang/lib/Sema/SemaExprObjC.cpp
parent7deb447781bee7639ffb12a31c8e4f74a2ba9db8 (diff)
downloadbcm5719-llvm-280e1ee0ae44f161971539ad6ab965169b932ae9.tar.gz
bcm5719-llvm-280e1ee0ae44f161971539ad6ab965169b932ae9.zip
Teach typo correction about various language keywords. We can't
generally recover from typos in keywords (since we would effectively have to mangle the token stream). However, there are still benefits to typo-correcting with keywords: - We don't make stupid suggestions when the user typed something that is similar to a keyword. - We can suggest the keyword in a diagnostic (did you mean "static_cast"?), even if we can't recover and therefore don't have a fix-it. llvm-svn: 101274
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index f7d76b8b9b6..faa1ffc31e2 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -372,7 +372,7 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
// Attempt to correct for typos in property names.
LookupResult Res(*this, MemberName, MemberLoc, LookupOrdinaryName);
- if (CorrectTypo(Res, 0, 0, IFace, false, OPT) &&
+ if (CorrectTypo(Res, 0, 0, IFace, false, CTC_NoKeywords, OPT) &&
Res.getAsSingle<ObjCPropertyDecl>()) {
DeclarationName TypoResult = Res.getLookupName();
Diag(MemberLoc, diag::err_property_not_found_suggest)
@@ -523,18 +523,37 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
}
}
- if (CorrectTypo(Result, S, 0) && Result.isSingleResult()) {
- NamedDecl *ND = Result.getFoundDecl();
- if (isa<ObjCInterfaceDecl>(ND)) {
+ // Determine our typo-correction context.
+ CorrectTypoContext CTC = CTC_Expression;
+ if (ObjCMethodDecl *Method = getCurMethodDecl())
+ if (Method->getClassInterface() &&
+ Method->getClassInterface()->getSuperClass())
+ CTC = CTC_ObjCMessageReceiver;
+
+ if (DeclarationName Corrected = CorrectTypo(Result, S, 0, 0, false, CTC)) {
+ if (Result.isSingleResult()) {
+ // If we found a declaration, correct when it refers to an Objective-C
+ // class.
+ NamedDecl *ND = Result.getFoundDecl();
+ if (isa<ObjCInterfaceDecl>(ND)) {
+ Diag(NameLoc, diag::err_unknown_receiver_suggest)
+ << Name << Result.getLookupName()
+ << FixItHint::CreateReplacement(SourceRange(NameLoc),
+ ND->getNameAsString());
+ Diag(ND->getLocation(), diag::note_previous_decl)
+ << Corrected;
+
+ Name = ND->getIdentifier();
+ return ObjCClassMessage;
+ }
+ } else if (Result.empty() && Corrected.getAsIdentifierInfo() &&
+ Corrected.getAsIdentifierInfo()->isStr("super")) {
+ // If we've found the keyword "super", this is a send to super.
Diag(NameLoc, diag::err_unknown_receiver_suggest)
- << Name << Result.getLookupName()
- << FixItHint::CreateReplacement(SourceRange(NameLoc),
- ND->getNameAsString());
- Diag(ND->getLocation(), diag::note_previous_decl)
- << ND->getDeclName();
-
- Name = ND->getIdentifier();
- return ObjCClassMessage;
+ << Name << Corrected
+ << FixItHint::CreateReplacement(SourceRange(NameLoc), "super");
+ Name = Corrected.getAsIdentifierInfo();
+ return ObjCSuperMessage;
}
}
OpenPOWER on IntegriCloud