@@ -2508,10 +2508,11 @@ void swift::performAbstractFuncDeclDiagnostics(TypeChecker &TC,
2508
2508
2509
2509
// / Diagnose C style for loops.
2510
2510
2511
- enum OperatorKind {
2511
+ namespace {
2512
+ enum class OperatorKind {
2512
2513
Greater,
2513
2514
Smaller,
2514
- NEqual ,
2515
+ NotEqual ,
2515
2516
};
2516
2517
2517
2518
static Expr *endConditionValueForConvertingCStyleForLoop (const ForStmt *FS,
@@ -2535,7 +2536,7 @@ static Expr *endConditionValueForConvertingCStyleForLoop(const ForStmt *FS,
2535
2536
// Verify that the condition is a simple != or < comparison to the loop variable.
2536
2537
auto comparisonOpName = binaryFuncExpr->getDecl ()->getNameStr ();
2537
2538
if (comparisonOpName == " !=" )
2538
- OpKind = OperatorKind::NEqual ;
2539
+ OpKind = OperatorKind::NotEqual ;
2539
2540
else if (comparisonOpName == " <" )
2540
2541
OpKind = OperatorKind::Smaller;
2541
2542
else if (comparisonOpName == " >" )
@@ -2557,7 +2558,7 @@ static Expr *endConditionValueForConvertingCStyleForLoop(const ForStmt *FS,
2557
2558
2558
2559
static bool unaryOperatorCheckForConvertingCStyleForLoop (const ForStmt *FS,
2559
2560
VarDecl *loopVar,
2560
- StringRef OpContent ) {
2561
+ StringRef OpName ) {
2561
2562
auto *Increment = FS->getIncrement ().getPtrOrNull ();
2562
2563
if (!Increment)
2563
2564
return false ;
@@ -2575,7 +2576,7 @@ static bool unaryOperatorCheckForConvertingCStyleForLoop(const ForStmt *FS,
2575
2576
auto unaryFuncExpr = dyn_cast<DeclRefExpr>(unaryExpr->getFn ());
2576
2577
if (!unaryFuncExpr)
2577
2578
return false ;
2578
- if (unaryFuncExpr->getDecl ()->getNameStr () != OpContent )
2579
+ if (unaryFuncExpr->getDecl ()->getNameStr () != OpName )
2579
2580
return false ;
2580
2581
return incrementDeclRefExpr->getDecl () == loopVar;
2581
2582
}
@@ -2594,7 +2595,7 @@ static bool unaryDecrementForConvertingCStyleForLoop(const ForStmt *FS,
2594
2595
static bool binaryOperatorCheckForConvertingCStyleForLoop (TypeChecker &TC,
2595
2596
const ForStmt *FS,
2596
2597
VarDecl *loopVar,
2597
- StringRef OpContent ) {
2598
+ StringRef OpName ) {
2598
2599
auto *Increment = FS->getIncrement ().getPtrOrNull ();
2599
2600
if (!Increment)
2600
2601
return false ;
@@ -2604,7 +2605,7 @@ static bool binaryOperatorCheckForConvertingCStyleForLoop(TypeChecker &TC,
2604
2605
auto binaryFuncExpr = dyn_cast<DeclRefExpr>(binaryExpr->getFn ());
2605
2606
if (!binaryFuncExpr)
2606
2607
return false ;
2607
- if (binaryFuncExpr->getDecl ()->getNameStr () != OpContent )
2608
+ if (binaryFuncExpr->getDecl ()->getNameStr () != OpName )
2608
2609
return false ;
2609
2610
auto argTupleExpr = dyn_cast<TupleExpr>(binaryExpr->getArg ());
2610
2611
if (!argTupleExpr)
@@ -2690,11 +2691,11 @@ static void checkCStyleForLoop(TypeChecker &TC, const ForStmt *FS) {
2690
2691
2691
2692
if (strideByOne && OpKind != OperatorKind::Greater) {
2692
2693
diagnostic
2693
- .fixItRemoveChars (loopVarDecl->getLoc (), loopVar->getLoc ())
2694
- .fixItReplaceChars (loopPatternEnd, startValue->getStartLoc (), " in " )
2695
- .fixItReplaceChars (FS->getFirstSemicolonLoc (), endValue->getStartLoc (),
2694
+ .fixItRemoveChars (loopVarDecl->getLoc (), loopVar->getLoc ())
2695
+ .fixItReplaceChars (loopPatternEnd, startValue->getStartLoc (), " in " )
2696
+ .fixItReplaceChars (FS->getFirstSemicolonLoc (), endValue->getStartLoc (),
2696
2697
" ..< " )
2697
- .fixItRemoveChars (FS->getSecondSemicolonLoc (), endOfIncrementLoc);
2698
+ .fixItRemoveChars (FS->getSecondSemicolonLoc (), endOfIncrementLoc);
2698
2699
return ;
2699
2700
} else if (strideBackByOne && OpKind != OperatorKind::Smaller) {
2700
2701
SourceLoc startValueEnd = Lexer::getLocForEndOfToken (TC.Context .SourceMgr ,
@@ -2704,14 +2705,14 @@ static void checkCStyleForLoop(TypeChecker &TC, const ForStmt *FS) {
2704
2705
Lexer::getLocForEndOfToken (TC.Context .SourceMgr , endValue->getEndLoc ())).str ();
2705
2706
2706
2707
diagnostic
2707
- .fixItRemoveChars (loopVarDecl->getLoc (), loopVar->getLoc ())
2708
- .fixItReplaceChars (loopPatternEnd, startValue->getStartLoc (), " in " )
2709
- .fixItInsert (startValue->getStartLoc (), (llvm::Twine (" ((" ) + endValueStr + " + 1)..." ).str ())
2710
- .fixItInsert (startValueEnd, " ).reversed()" )
2711
- .fixItRemoveChars (FS->getFirstSemicolonLoc (), endOfIncrementLoc);
2708
+ .fixItRemoveChars (loopVarDecl->getLoc (), loopVar->getLoc ())
2709
+ .fixItReplaceChars (loopPatternEnd, startValue->getStartLoc (), " in " )
2710
+ .fixItInsert (startValue->getStartLoc (), (llvm::Twine (" ((" ) + endValueStr + " + 1)..." ).str ())
2711
+ .fixItInsert (startValueEnd, " ).reversed()" )
2712
+ .fixItRemoveChars (FS->getFirstSemicolonLoc (), endOfIncrementLoc);
2712
2713
}
2713
2714
}
2714
-
2715
+ } // Anonymous namespace end.
2715
2716
2716
2717
// Perform MiscDiagnostics on Switch Statements.
2717
2718
static void checkSwitch (TypeChecker &TC, const SwitchStmt *stmt) {
0 commit comments