]> granicus.if.org Git - clang/commitdiff
[Tooling] Added DeclStmtClass to ExtractionSemicolonPolicy
authorShaurya Gupta <shauryab98@gmail.com>
Wed, 14 Aug 2019 13:37:39 +0000 (13:37 +0000)
committerShaurya Gupta <shauryab98@gmail.com>
Wed, 14 Aug 2019 13:37:39 +0000 (13:37 +0000)
Since the DeclStmt range includes the semicolon, it doesn't need a
semicolon at the end during extraction

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

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

index 09c89c15a97bb04b7764310b676f35383dc3606f..5d57ecf90a96df4c006741f52310e69f6628072b 100644 (file)
@@ -45,6 +45,7 @@ bool isSemicolonRequiredAfter(const Stmt *S) {
   if(const auto *Case = dyn_cast<SwitchCase>(S))
     return isSemicolonRequiredAfter(Case->getSubStmt());
   switch (S->getStmtClass()) {
+  case Stmt::DeclStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:
index 97f12475761986976c706d851bca454b37a6bace..865e8290923a0144e2eefe420541a938f650dc97 100644 (file)
@@ -193,7 +193,7 @@ void careForNonCompoundSemicolons2() {
 // CHECK-NEXT: }
 
 void careForSwitchSemicolon() {
-  /*range mextract=->+0:51*/switch(0) default: break;
+  /*range mextract=->+0:53*/switch(0) default: break;
 }
 // CHECK: 1 'mextract' results:
 // CHECK:      static void extracted() {
@@ -203,3 +203,14 @@ void careForSwitchSemicolon() {
 // CHECK-NEXT: extracted();{{$}}
 // CHECK-NEXT: }
 
+void extractStatementNotSemiDecl() {
+  /*range nextract=->+0:38*/int x = 5;
+}
+// CHECK: 1 'nextract' results:
+// CHECK:      static void extracted() {
+// CHECK-NEXT: int x = 5;{{$}}
+// CHECK-NEXT: }{{[[:space:]].*}}
+// CHECK-NEXT: void extractStatementNotSemiDecl() {
+// CHECK-NEXT: extracted();{{$}}
+// CHECK-NEXT: }
+