[英]find how many gotos are in a c++ project
I am trying to see how many goto
instructions are inside a c++ project. 我正在尝试查看c ++项目中有多少条
goto
指令。 Now I am using a simple matching with grep
searching for "goto "
: 现在,我正在使用与
grep
的简单匹配来搜索"goto "
:
grep -r --exclude-dir "third_party" --include "*.cpp" --include "*.h" --include "*.C" --include "*.cxx" --include "*.hcc" --include "*.c" --include "*.cc" "goto " .
I get a lot of fake positive, in particular inside comments: 我得到了很多假阳性,尤其是内部评论:
// Perform stack overflow check if this goto needs it before jumping.
or inside literals: 或内部文字:
stream->Add(" goto (");
what is the easiest way to avoid them? 避免它们的最简单方法是什么? I don't need a perfect solution.
我不需要完美的解决方案。
Change your regular expression to: 'goto[ \\t]+[_A-Za-z0-9]+[ \\t]*;'
将您的正则表达式更改为:
'goto[ \\t]+[_A-Za-z0-9]+[ \\t]*;'
This will search for the word goto, its target label and a semicolon all on the same line. 这将在同一行上搜索goto单词,其目标标签和一个分号。
I suggest using awk
or another tool that can use more than one regular expression or write a script. 我建议使用
awk
或另一种可以使用多个正则表达式或编写脚本的工具。
The more difficult cases are: 更困难的情况是:
/*****
* Goto system failure if this point is reached.
*/
Meaning anything inside C-style comments. 在C风格的注释中包含任何含义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.