mirror of
https://github.com/intel/llvm.git
synced 2026-02-07 07:39:11 +08:00
Tweak typo-correction logic a bit regarding "super", so that we
consider "super" as a candidate whenever we're parsing an expression within an Objective-C method in an interface that has a superclass. At some point, we'd like to give "super" a little edge over non-local names; that will come later. llvm-svn: 104022
This commit is contained in:
@@ -1811,7 +1811,8 @@ public:
|
||||
bool HasTrailingLParen,
|
||||
bool IsAddressOfOperand);
|
||||
|
||||
bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R);
|
||||
bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
|
||||
CorrectTypoContext CTC = CTC_Unknown);
|
||||
|
||||
OwningExprResult LookupInObjCMethod(LookupResult &R,
|
||||
Scope *S,
|
||||
|
||||
@@ -917,7 +917,7 @@ static void DiagnoseInstanceReference(Sema &SemaRef,
|
||||
///
|
||||
/// \return false if new lookup candidates were found
|
||||
bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS,
|
||||
LookupResult &R) {
|
||||
LookupResult &R, CorrectTypoContext CTC) {
|
||||
DeclarationName Name = R.getLookupName();
|
||||
|
||||
unsigned diagnostic = diag::err_undeclared_var_use;
|
||||
@@ -968,7 +968,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS,
|
||||
|
||||
// We didn't find anything, so try to correct for a typo.
|
||||
DeclarationName Corrected;
|
||||
if (S && (Corrected = CorrectTypo(R, S, &SS))) {
|
||||
if (S && (Corrected = CorrectTypo(R, S, &SS, false, CTC))) {
|
||||
if (!R.empty()) {
|
||||
if (isa<ValueDecl>(*R.begin()) || isa<FunctionTemplateDecl>(*R.begin())) {
|
||||
if (SS.isEmpty())
|
||||
@@ -1122,7 +1122,7 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S,
|
||||
// If this name wasn't predeclared and if this is not a function
|
||||
// call, diagnose the problem.
|
||||
if (R.empty()) {
|
||||
if (DiagnoseEmptyLookup(S, SS, R))
|
||||
if (DiagnoseEmptyLookup(S, SS, R, CTC_Unknown))
|
||||
return ExprError();
|
||||
|
||||
assert(!R.empty() &&
|
||||
|
||||
@@ -2612,6 +2612,12 @@ DeclarationName Sema::CorrectTypo(LookupResult &Res, Scope *S, CXXScopeSpec *SS,
|
||||
WantExpressionKeywords = true;
|
||||
WantCXXNamedCasts = true;
|
||||
WantRemainingKeywords = true;
|
||||
|
||||
if (ObjCMethodDecl *Method = getCurMethodDecl())
|
||||
if (Method->getClassInterface() &&
|
||||
Method->getClassInterface()->getSuperClass())
|
||||
Consumer.addKeywordResult(Context, "super");
|
||||
|
||||
break;
|
||||
|
||||
case CTC_NoKeywords:
|
||||
|
||||
@@ -6002,7 +6002,7 @@ BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
|
||||
|
||||
LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
|
||||
Sema::LookupOrdinaryName);
|
||||
if (SemaRef.DiagnoseEmptyLookup(S, SS, R))
|
||||
if (SemaRef.DiagnoseEmptyLookup(S, SS, R, Sema::CTC_Expression))
|
||||
return Destroy(SemaRef, Fn, Args, NumArgs);
|
||||
|
||||
assert(!R.empty() && "lookup results empty despite recovery");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -DNON_FIXITS -verify %s
|
||||
// RUN: %clang -E -P %s -o %t
|
||||
// RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fixit %t || true
|
||||
// RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fixit %t || true
|
||||
// RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -pedantic -Werror %t
|
||||
|
||||
@interface NSString // expected-note{{'NSString' declared here}}
|
||||
@@ -97,6 +97,7 @@ void test2(Collide *a) {
|
||||
|
||||
@interface Super
|
||||
- (int)method; // expected-note{{using}}
|
||||
- (int)method2;
|
||||
@end
|
||||
|
||||
@interface Sub : Super
|
||||
@@ -110,6 +111,20 @@ void test2(Collide *a) {
|
||||
|
||||
@end
|
||||
|
||||
#ifdef NON_FIXITS
|
||||
double *isupper(int);
|
||||
|
||||
@interface Sub2 : Super
|
||||
- (int)method2;
|
||||
@end
|
||||
|
||||
@implementation Sub2
|
||||
- (int)method2 {
|
||||
return [supper method2]; // expected-error{{use of undeclared identifier 'supper'}}
|
||||
}
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface Ivar
|
||||
@end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user