我想找到所有没有 break 语句的 case 语句。我使用 clang-query 来构建我的匹配器。我的匹配器在某些测试用例中失败。
我写了简单的匹配器
匹配 caseStmt(除非(有(breakStmt())))
它适用于以下测试用例
#include<stdlib.h>
int main(){
int x;
switch(x){
case 1:
break;
case 2:
default:
x++;
}
return 0;
}
int main()
{
int x = 1, y = 2;
// Outer Switch
switch (x) {
// If x == 1
case 1:
// Nested Switch
switch (y) {
// If y == 2
case 2:
//break;
// If y == 3
case 3:
break;
}
break;
// If x == 4
case 4:
break;
// If x == 5
case 5:
break;
default:
break;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int x = 1, y = 2;
// Outer Switch
switch (x) {
// If x == 1
case 1:
// Nested Switch
switch (y) {
// If y == 2
case 2:
cout << "Choice is 2";
//break;
// If y == 3
case 3:
cout << "Choice is 3";
break;
}
//break;
// If x == 4
case 4:
cout << "Choice is 4";
break;
// If x == 5
case 5:
cout << "Choice is 5";
break;
default:
cout << "Choice is other than 1, 2 3, 4, or 5";
break;
}
return 0;
}
在上述情况下,它显示了带有 break 语句的 case 语句以及没有 break 语句的 case 语句。
我在做什么错?请帮助:)我正在关注这个 http://releases.llvm.org/8.0.0/tools/clang/docs/LibASTMatchersTutorial.html