diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-03 18:01:57 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-03 18:01:57 +0000 |
commit | 35b0bac8c51afaa9afe168d9f3f13a6da846bc63 (patch) | |
tree | effe30e9e3a688899966fd41471531d593a1af69 /clang/lib/Sema/SemaExpr.cpp | |
parent | 48218e42cd78e85badedd7f36ea39c730314281e (diff) | |
download | bcm5719-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/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index feb6b2b666e..a8be3339678 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1059,6 +1059,16 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S, assert(!R.empty() && "DiagnoseEmptyLookup returned false but added no results"); + + // If we found an Objective-C instance variable, let + // LookupInObjCMethod build the appropriate expression to + // reference the ivar. + if (ObjCIvarDecl *Ivar = R.getAsSingle<ObjCIvarDecl>()) { + R.clear(); + OwningExprResult E(LookupInObjCMethod(R, S, Ivar->getIdentifier())); + assert(E.isInvalid() || E.get()); + return move(E); + } } } @@ -2848,6 +2858,20 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, ObjCInterfaceDecl *ClassDeclared; ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared); + if (!IV) { + // Attempt to correct for typos in ivar names. + LookupResult Res(*this, R.getLookupName(), R.getNameLoc(), + LookupMemberName); + if (CorrectTypo(Res, 0, 0, IDecl) && + (IV = Res.getAsSingle<ObjCIvarDecl>())) { + Diag(R.getNameLoc(), + diag::err_typecheck_member_reference_ivar_suggest) + << IDecl->getDeclName() << MemberName << IV->getDeclName() + << CodeModificationHint::CreateReplacement(R.getNameLoc(), + IV->getNameAsString()); + } + } + if (IV) { // If the decl being referenced had an error, return an error for this // sub-expr without emitting another error, in order to avoid cascading @@ -3014,6 +3038,20 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, return Owned(new (Context) ObjCImplicitSetterGetterRefExpr(Getter, PType, Setter, MemberLoc, BaseExpr)); } + + // Attempt to correct for typos in property names. + LookupResult Res(*this, R.getLookupName(), R.getNameLoc(), + LookupOrdinaryName); + if (CorrectTypo(Res, 0, 0, IFace, false, OPT) && + Res.getAsSingle<ObjCPropertyDecl>()) { + Diag(R.getNameLoc(), diag::err_property_not_found_suggest) + << MemberName << BaseType << Res.getLookupName() + << CodeModificationHint::CreateReplacement(R.getNameLoc(), + Res.getLookupName().getAsString()); + return LookupMemberExpr(Res, BaseExpr, IsArrow, OpLoc, SS, + FirstQualifierInScope, ObjCImpDecl); + } + return ExprError(Diag(MemberLoc, diag::err_property_not_found) << MemberName << BaseType); } |