【发布时间】:2019-08-06 21:13:17
【问题描述】:
我想找到所有没有 break 语句的 case 语句。我使用 clang-query 来构建我的匹配器。我的匹配器在某些测试用例中失败了。
我把简单的匹配器写成
匹配 caseStmt(除非(has(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
【问题讨论】:
标签: clang llvm llvm-clang clang-ast-matchers clang-query