[Extract] Fixed SemicolonExtractionPolicy for SwitchStmt and SwitchCase

Reviewers: arphaman, sammccall

Subscribers: dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65883

llvm-svn: 368267
This commit is contained in:
Shaurya Gupta 2019-08-08 08:37:49 +00:00
parent bac7862c00
commit 7137736e49
2 changed files with 17 additions and 1 deletions

View File

@ -40,8 +40,11 @@ bool isSemicolonRequiredAfter(const Stmt *S) {
return isSemicolonRequiredAfter(CXXFor->getBody()); return isSemicolonRequiredAfter(CXXFor->getBody());
if (const auto *ObjCFor = dyn_cast<ObjCForCollectionStmt>(S)) if (const auto *ObjCFor = dyn_cast<ObjCForCollectionStmt>(S))
return isSemicolonRequiredAfter(ObjCFor->getBody()); return isSemicolonRequiredAfter(ObjCFor->getBody());
if(const auto *Switch = dyn_cast<SwitchStmt>(S))
return isSemicolonRequiredAfter(Switch->getBody());
if(const auto *Case = dyn_cast<SwitchCase>(S))
return isSemicolonRequiredAfter(Case->getSubStmt());
switch (S->getStmtClass()) { switch (S->getStmtClass()) {
case Stmt::SwitchStmtClass:
case Stmt::CXXTryStmtClass: case Stmt::CXXTryStmtClass:
case Stmt::ObjCAtSynchronizedStmtClass: case Stmt::ObjCAtSynchronizedStmtClass:
case Stmt::ObjCAutoreleasePoolStmtClass: case Stmt::ObjCAutoreleasePoolStmtClass:

View File

@ -64,6 +64,7 @@ void extractStatementNotSemiSwitch() {
// CHECK-NEXT: extracted();{{$}} // CHECK-NEXT: extracted();{{$}}
// CHECK-NEXT: } // CHECK-NEXT: }
void extractStatementNotSemiWhile() { void extractStatementNotSemiWhile() {
/*range eextract=->+2:4*/while (true) { /*range eextract=->+2:4*/while (true) {
int x = 0; int x = 0;
@ -190,3 +191,15 @@ void careForNonCompoundSemicolons2() {
// CHECK-NEXT: extracted();{{$}} // CHECK-NEXT: extracted();{{$}}
// CHECK-NEXT: // // CHECK-NEXT: //
// CHECK-NEXT: } // CHECK-NEXT: }
void careForSwitchSemicolon() {
/*range mextract=->+0:51*/switch(0) default: break;
}
// CHECK: 1 'mextract' results:
// CHECK: static void extracted() {
// CHECK-NEXT: switch(0) default: break;{{$}}
// CHECK-NEXT: }{{[[:space:]].*}}
// CHECK-NEXT: void careForSwitchSemicolon() {
// CHECK-NEXT: extracted();{{$}}
// CHECK-NEXT: }