summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-03 18:01:57 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-03 18:01:57 +0000
commit35b0bac8c51afaa9afe168d9f3f13a6da846bc63 (patch)
treeeffe30e9e3a688899966fd41471531d593a1af69 /clang/lib/Sema/SemaDecl.cpp
parent48218e42cd78e85badedd7f36ea39c730314281e (diff)
downloadbcm5719-llvm-35b0bac8c51afaa9afe168d9f3f13a6da846bc63.tar.gz
bcm5719-llvm-35b0bac8c51afaa9afe168d9f3f13a6da846bc63.zip
Implement typo correction for a variety of Objective-C-specific
constructs: - Instance variable lookup ("foo->ivar" and, in instance methods, "ivar") - Property name lookup ("foo.prop") - Superclasses - Various places where a class name is required - Protocol names (e.g., id<proto>) This seems to cover many of the common places where typos could occur. llvm-svn: 92449
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2253f093df0..30f90400007 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -555,11 +555,35 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
/// getObjCInterfaceDecl - Look up a for a class declaration in the scope.
/// return 0 if one not found.
-ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *Id) {
+///
+/// \param Id the name of the Objective-C class we're looking for. If
+/// typo-correction fixes this name, the Id will be updated
+/// to the fixed name.
+///
+/// \param RecoverLoc if provided, this routine will attempt to
+/// recover from a typo in the name of an existing Objective-C class
+/// and, if successful, will return the lookup that results from
+/// typo-correction.
+ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *&Id,
+ SourceLocation RecoverLoc) {
// The third "scope" argument is 0 since we aren't enabling lazy built-in
// creation from this context.
NamedDecl *IDecl = LookupSingleName(TUScope, Id, LookupOrdinaryName);
+ if (!IDecl && !RecoverLoc.isInvalid()) {
+ // Perform typo correction at the given location, but only if we
+ // find an Objective-C class name.
+ LookupResult R(*this, Id, RecoverLoc, LookupOrdinaryName);
+ if (CorrectTypo(R, TUScope, 0) &&
+ (IDecl = R.getAsSingle<ObjCInterfaceDecl>())) {
+ Diag(RecoverLoc, diag::err_undef_interface_suggest)
+ << Id << IDecl->getDeclName()
+ << CodeModificationHint::CreateReplacement(RecoverLoc,
+ IDecl->getNameAsString());
+ Id = IDecl->getIdentifier();
+ }
+ }
+
return dyn_cast_or_null<ObjCInterfaceDecl>(IDecl);
}
OpenPOWER on IntegriCloud