Make the callback object to Sema::CorrectTypo mandatory.

llvm-svn: 149451
This commit is contained in:
Kaelyn Uhrain 2012-01-31 23:49:25 +00:00
parent 440e9db9e7
commit 4e8942c139
12 changed files with 30 additions and 31 deletions

View File

@ -1786,7 +1786,7 @@ public:
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
Sema::LookupNameKind LookupKind,
Scope *S, CXXScopeSpec *SS,
CorrectionCandidateCallback *CCC,
CorrectionCandidateCallback &CCC,
DeclContext *MemberContext = 0,
bool EnteringContext = false,
const ObjCObjectPointerType *OPT = 0);

View File

@ -500,7 +500,7 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S,
TypoCorrection Corrected;
Found.clear();
if ((Corrected = CorrectTypo(Found.getLookupNameInfo(),
Found.getLookupKind(), S, &SS, &Validator,
Found.getLookupKind(), S, &SS, Validator,
LookupCtx, EnteringContext))) {
std::string CorrectedStr(Corrected.getAsString(getLangOptions()));
std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions()));

View File

@ -174,7 +174,7 @@ ParsedType Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
if (CorrectedII) {
TypeNameValidatorCCC Validator(true);
TypoCorrection Correction = CorrectTypo(Result.getLookupNameInfo(),
Kind, S, SS, &Validator);
Kind, S, SS, Validator);
IdentifierInfo *NewII = Correction.getCorrectionAsIdentifierInfo();
TemplateTy Template;
bool MemberOfUnknownSpecialization;
@ -371,7 +371,7 @@ bool Sema::DiagnoseUnknownTypeName(const IdentifierInfo &II,
TypeNameValidatorCCC Validator(false);
if (TypoCorrection Corrected = CorrectTypo(DeclarationNameInfo(&II, IILoc),
LookupOrdinaryName, S, SS,
&Validator)) {
Validator)) {
std::string CorrectedStr(Corrected.getAsString(getLangOptions()));
std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions()));
@ -576,7 +576,7 @@ Corrected:
CorrectionCandidateCallback DefaultValidator;
if (TypoCorrection Corrected = CorrectTypo(Result.getLookupNameInfo(),
Result.getLookupKind(), S,
&SS, &DefaultValidator)) {
&SS, DefaultValidator)) {
unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
unsigned QualifiedDiag = diag::err_no_member_suggest;
std::string CorrectedStr(Corrected.getAsString(getLangOptions()));
@ -1274,7 +1274,7 @@ ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *&Id,
DeclFilterCCC<ObjCInterfaceDecl> Validator;
if (TypoCorrection C = CorrectTypo(DeclarationNameInfo(Id, IdLoc),
LookupOrdinaryName, TUScope, NULL,
&Validator)) {
Validator)) {
IDecl = C.getCorrectionDeclAs<ObjCInterfaceDecl>();
Diag(IdLoc, diag::err_undef_interface_suggest)
<< Id << IDecl->getDeclName()
@ -4498,7 +4498,7 @@ static NamedDecl* DiagnoseInvalidRedeclaration(
// If the qualified name lookup yielded nothing, try typo correction
} else if ((Correction = SemaRef.CorrectTypo(Prev.getLookupNameInfo(),
Prev.getLookupKind(), 0, 0,
&Validator, NewDC))) {
Validator, NewDC))) {
// Trap errors.
Sema::SFINAETrap Trap(SemaRef);
@ -7359,7 +7359,7 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
TypoCorrection Corrected;
DeclFilterCCC<FunctionDecl> Validator;
if (S && (Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc),
LookupOrdinaryName, S, 0, &Validator))) {
LookupOrdinaryName, S, 0, Validator))) {
std::string CorrectedStr = Corrected.getAsString(getLangOptions());
std::string CorrectedQuotedStr = Corrected.getQuoted(getLangOptions());
FunctionDecl *Func = Corrected.getCorrectionDeclAs<FunctionDecl>();

View File

@ -1882,7 +1882,7 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
MemInitializerValidatorCCC Validator(ClassDecl);
if (R.empty() && BaseType.isNull() &&
(Corr = CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, &SS,
&Validator, ClassDecl))) {
Validator, ClassDecl))) {
std::string CorrectedStr(Corr.getAsString(getLangOptions()));
std::string CorrectedQuotedStr(Corr.getQuoted(getLangOptions()));
if (FieldDecl *Member = Corr.getCorrectionDeclAs<FieldDecl>()) {
@ -5953,7 +5953,7 @@ static bool TryNamespaceTypoCorrection(Sema &S, LookupResult &R, Scope *Sc,
R.clear();
if (TypoCorrection Corrected = S.CorrectTypo(R.getLookupNameInfo(),
R.getLookupKind(), Sc, &SS,
&Validator)) {
Validator)) {
std::string CorrectedStr(Corrected.getAsString(S.getLangOptions()));
std::string CorrectedQuotedStr(Corrected.getQuoted(S.getLangOptions()));
if (DeclContext *DC = S.computeDeclContext(SS, false))

View File

@ -423,7 +423,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
ObjCInterfaceValidatorCCC Validator(IDecl);
if (TypoCorrection Corrected = CorrectTypo(
DeclarationNameInfo(SuperName, SuperLoc), LookupOrdinaryName, TUScope,
NULL, &Validator)) {
NULL, Validator)) {
PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>();
Diag(SuperLoc, diag::err_undef_superclass_suggest)
<< SuperName << ClassName << PrevDecl->getDeclName();
@ -655,7 +655,7 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
DeclFilterCCC<ObjCProtocolDecl> Validator;
TypoCorrection Corrected = CorrectTypo(
DeclarationNameInfo(ProtocolId[i].first, ProtocolId[i].second),
LookupObjCProtocolName, TUScope, NULL, &Validator);
LookupObjCProtocolName, TUScope, NULL, Validator);
if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>())) {
Diag(ProtocolId[i].second, diag::err_undeclared_protocol_suggest)
<< ProtocolId[i].first << Corrected.getCorrection();
@ -893,7 +893,7 @@ Decl *Sema::ActOnStartClassImplementation(
ObjCInterfaceValidatorCCC Validator;
if (TypoCorrection Corrected = CorrectTypo(
DeclarationNameInfo(ClassName, ClassLoc), LookupOrdinaryName, TUScope,
NULL, &Validator)) {
NULL, Validator)) {
// Suggest the (potentially) correct interface name. However, put the
// fix-it hint itself in a separate note, since changing the name in
// the warning would make the fix-it change semantics.However, don't

View File

@ -1611,7 +1611,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
// We didn't find anything, so try to correct for a typo.
TypoCorrection Corrected;
if (S && (Corrected = CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(),
S, &SS, &CCC))) {
S, &SS, CCC))) {
std::string CorrectedStr(Corrected.getAsString(getLangOptions()));
std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions()));
R.setLookupName(Corrected.getCorrection());

View File

@ -583,7 +583,7 @@ LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
RecordMemberExprValidatorCCC Validator;
TypoCorrection Corrected = SemaRef.CorrectTypo(R.getLookupNameInfo(),
R.getLookupKind(), NULL,
&SS, &Validator, DC);
&SS, Validator, DC);
R.clear();
if (NamedDecl *ND = Corrected.getCorrectionDecl()) {
std::string CorrectedStr(
@ -1124,7 +1124,7 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
Validator.IsObjCIvarLookup = IsArrow;
if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(),
LookupMemberName, NULL, NULL,
&Validator, IDecl)) {
Validator, IDecl)) {
IV = Corrected.getCorrectionDeclAs<ObjCIvarDecl>();
Diag(R.getNameLoc(),
diag::err_typecheck_member_reference_ivar_suggest)

View File

@ -704,7 +704,7 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
DeclFilterCCC<ObjCPropertyDecl> Validator;
if (TypoCorrection Corrected = CorrectTypo(
DeclarationNameInfo(MemberName, MemberLoc), LookupOrdinaryName, NULL,
NULL, &Validator, IFace, false, OPT)) {
NULL, Validator, IFace, false, OPT)) {
ObjCPropertyDecl *Property =
Corrected.getCorrectionDeclAs<ObjCPropertyDecl>();
DeclarationName TypoResult = Corrected.getCorrection();
@ -936,7 +936,7 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
ObjCInterfaceOrSuperCCC Validator(getCurMethodDecl());
if (TypoCorrection Corrected = CorrectTypo(Result.getLookupNameInfo(),
Result.getLookupKind(), S, NULL,
&Validator)) {
Validator)) {
if (Corrected.isKeyword()) {
// If we've found the keyword "super" (the only keyword that would be
// returned by CorrectTypo), this is a send to super.

View File

@ -1711,7 +1711,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
FieldInitializerValidatorCCC Validator(RT->getDecl());
TypoCorrection Corrected = SemaRef.CorrectTypo(
DeclarationNameInfo(FieldName, D->getFieldLoc()),
Sema::LookupMemberName, /*Scope=*/0, /*SS=*/0, &Validator,
Sema::LookupMemberName, /*Scope=*/0, /*SS=*/0, Validator,
RT->getDecl());
if (Corrected) {
std::string CorrectedStr(

View File

@ -3536,7 +3536,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
Sema::LookupNameKind LookupKind,
Scope *S, CXXScopeSpec *SS,
CorrectionCandidateCallback *CCC,
CorrectionCandidateCallback &CCC,
DeclContext *MemberContext,
bool EnteringContext,
const ObjCObjectPointerType *OPT) {
@ -3572,7 +3572,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
// If a callback object returns true for an empty typo correction candidate,
// assume it does not do any actual validation of the candidates.
TypoCorrection EmptyCorrection;
bool ValidatingCallback = CCC && !CCC->ValidateCandidate(EmptyCorrection);
bool ValidatingCallback = !CCC.ValidateCandidate(EmptyCorrection);
// Perform name lookup to find visible, similarly-named entities.
bool IsUnqualifiedLookup = false;
@ -3608,7 +3608,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
// keyword case, we'll end up adding the keyword below.
if (Cached->second) {
if (!Cached->second.isKeyword() &&
(!CCC || CCC->ValidateCandidate(Cached->second)))
CCC.ValidateCandidate(Cached->second))
Consumer.addCorrection(Cached->second);
} else {
// Only honor no-correction cache hits when a callback that will validate
@ -3646,8 +3646,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
}
}
CorrectionCandidateCallback DefaultCCC;
AddKeywordsToConsumer(*this, Consumer, S, CCC ? *CCC : DefaultCCC);
AddKeywordsToConsumer(*this, Consumer, S, CCC);
// If we haven't found anything, we're done.
if (Consumer.empty()) {
@ -3704,7 +3703,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
if (I->second.isResolved()) {
TypoCorrectionConsumer::result_iterator Prev = I;
++I;
if (CCC && !CCC->ValidateCandidate(Prev->second))
if (!CCC.ValidateCandidate(Prev->second))
DI->second->erase(Prev);
continue;
}
@ -3712,7 +3711,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
// Perform name lookup on this name.
IdentifierInfo *Name = I->second.getCorrectionAsIdentifierInfo();
LookupPotentialTypoResult(*this, TmpRes, Name, S, SS, MemberContext,
EnteringContext, CCC && CCC->IsObjCIvarLookup);
EnteringContext, CCC.IsObjCIvarLookup);
switch (TmpRes.getResultKind()) {
case LookupResult::NotFound:
@ -3741,7 +3740,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
TRD != TRDEnd; ++TRD)
I->second.addCorrectionDecl(*TRD);
++I;
if (CCC && !CCC->ValidateCandidate(Prev->second))
if (!CCC.ValidateCandidate(Prev->second))
DI->second->erase(Prev);
break;
}
@ -3750,7 +3749,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
TypoCorrectionConsumer::result_iterator Prev = I;
I->second.setCorrectionDecl(TmpRes.getAsSingle<NamedDecl>());
++I;
if (CCC && !CCC->ValidateCandidate(Prev->second))
if (!CCC.ValidateCandidate(Prev->second))
DI->second->erase(Prev);
break;
}
@ -3868,7 +3867,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
// WantObjCSuper is only true for CTC_ObjCMessageReceiver and for
// some instances of CTC_Unknown, while WantRemainingKeywords is true
// for CTC_Unknown but not for CTC_ObjCMessageReceiver.
&& CCC && CCC->WantObjCSuper && !CCC->WantRemainingKeywords
&& CCC.WantObjCSuper && !CCC.WantRemainingKeywords
&& BestResults["super"].isKeyword()) {
// Prefer 'super' when we're completing in a message-receiver
// context.

View File

@ -310,7 +310,7 @@ void Sema::LookupTemplateName(LookupResult &Found,
FilterCCC.WantCXXNamedCasts = true;
if (TypoCorrection Corrected = CorrectTypo(Found.getLookupNameInfo(),
Found.getLookupKind(), S, &SS,
&FilterCCC, LookupCtx)) {
FilterCCC, LookupCtx)) {
Found.setLookupName(Corrected.getCorrection());
if (Corrected.getCorrectionDecl())
Found.addDecl(Corrected.getCorrectionDecl());

View File

@ -753,7 +753,7 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S,
case LookupResult::NotFoundInCurrentInstantiation:
if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(),
R.getLookupKind(), S, 0,
&Validator)) {
Validator)) {
std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions()));
ParameterPack = Corrected.getCorrectionDecl();
Diag(NameLoc, diag::err_sizeof_pack_no_pack_name_suggest)