diff options
| author | Kaelyn Uhrain <rikka@google.com> | 2012-01-12 19:27:05 +0000 |
|---|---|---|
| committer | Kaelyn Uhrain <rikka@google.com> | 2012-01-12 19:27:05 +0000 |
| commit | b02c5e9356a1b7176d86ee54b521b5a05daacbb3 (patch) | |
| tree | ec01d9eb22af4ad975ddabcd688b903896a3ad5a /clang/lib | |
| parent | 3d3aea9374d745d76f9b448e42dec0d56d5f54ab (diff) | |
| download | bcm5719-llvm-b02c5e9356a1b7176d86ee54b521b5a05daacbb3.tar.gz bcm5719-llvm-b02c5e9356a1b7176d86ee54b521b5a05daacbb3.zip | |
Convert SemaInit.cpp to pass a callback object to CorrectTypo.
And once again improve the typo correction results in certain
situations just by moving the existing checks on the correction.
llvm-svn: 148037
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index bcb624be899..a4282e29462 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1529,6 +1529,26 @@ static DesignatedInitExpr *CloneDesignatedInitExpr(Sema &SemaRef, DIE->usesGNUSyntax(), DIE->getInit()); } +namespace { + +// Callback to only accept typo corrections that are for field members of +// the given struct or union. +class FieldInitializerValidatorCCC : public CorrectionCandidateCallback { + public: + explicit FieldInitializerValidatorCCC(RecordDecl *RD) + : Record(RD) {} + + virtual bool ValidateCandidate(const TypoCorrection &candidate) { + FieldDecl *FD = candidate.getCorrectionDeclAs<FieldDecl>(); + return FD && FD->getDeclContext()->getRedeclContext()->Equals(Record); + } + + private: + RecordDecl *Record; +}; + +} + /// @brief Check the well-formedness of a C99 designated initializer. /// /// Determines whether the designated initializer @p DIE, which @@ -1687,19 +1707,17 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, if (Lookup.first == Lookup.second) { // Name lookup didn't find anything. Determine whether this // was a typo for another field name. - LookupResult R(SemaRef, FieldName, D->getFieldLoc(), - Sema::LookupMemberName); + FieldInitializerValidatorCCC Validator(RT->getDecl()); TypoCorrection Corrected = SemaRef.CorrectTypo( DeclarationNameInfo(FieldName, D->getFieldLoc()), - Sema::LookupMemberName, /*Scope=*/NULL, /*SS=*/NULL, - RT->getDecl(), false, Sema::CTC_NoKeywords); - if ((ReplacementField = Corrected.getCorrectionDeclAs<FieldDecl>()) && - ReplacementField->getDeclContext()->getRedeclContext() - ->Equals(RT->getDecl())) { + Sema::LookupMemberName, /*Scope=*/0, /*SS=*/0, &Validator, + RT->getDecl()); + if (Corrected) { std::string CorrectedStr( Corrected.getAsString(SemaRef.getLangOptions())); std::string CorrectedQuotedStr( Corrected.getQuoted(SemaRef.getLangOptions())); + ReplacementField = Corrected.getCorrectionDeclAs<FieldDecl>(); SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_unknown_suggest) << FieldName << CurrentObjectType << CorrectedQuotedStr |

