]> granicus.if.org Git - clang/commitdiff
[Extract] Fixed SemicolonExtractionPolicy for SwitchStmt and SwitchCase
authorShaurya Gupta <shauryab98@gmail.com>
Thu, 8 Aug 2019 08:37:49 +0000 (08:37 +0000)
committerShaurya Gupta <shauryab98@gmail.com>
Thu, 8 Aug 2019 08:37:49 +0000 (08:37 +0000)
Reviewers: arphaman, sammccall

Subscribers: dexonsmith, cfe-commits

Tags: #clang

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368267 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
test/Refactor/Extract/ExtractionSemicolonPolicy.cpp

index 533c373e35c4584b88ecf2e0826a9bebcd81243c..9b0c37b1709a253778b306e92b75037b00142b62 100644 (file)
@@ -40,8 +40,11 @@ bool isSemicolonRequiredAfter(const Stmt *S) {
     return isSemicolonRequiredAfter(CXXFor->getBody());
   if (const auto *ObjCFor = dyn_cast<ObjCForCollectionStmt>(S))
     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()) {
-  case Stmt::SwitchStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:
index 5caf9d4526844f3fad63da0e6ccab8c279d13bde..97f12475761986976c706d851bca454b37a6bace 100644 (file)
@@ -64,6 +64,7 @@ void extractStatementNotSemiSwitch() {
 // CHECK-NEXT: extracted();{{$}}
 // CHECK-NEXT: }
 
+
 void extractStatementNotSemiWhile() {
   /*range eextract=->+2:4*/while (true) {
     int x = 0;
@@ -190,3 +191,15 @@ void careForNonCompoundSemicolons2() {
 // CHECK-NEXT: extracted();{{$}}
 // 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: }
+