Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
cppcheck 非常棒。
cppcheck is just wonderful.
Google 有一个有趣的工具及其风格指南...称为 cpplint。它可能有助于生成更清晰的代码。看看吧。
http://code.google .com/p/google-styleguide/source/browse/trunk/cpplint/cpplint.py?r=15
Google has an interesting tool along with its style guide... called cpplint. It may be helpful for generating cleaner code. Have a look.
http://code.google.com/p/google-styleguide/source/browse/trunk/cpplint/cpplint.py?r=15
clang 可以进行静态分析。
clang can do static analysis.
关于查找常量,我们的 SD 源代码搜索引擎 (SCSE) 可以现成地执行此操作。 SCSE 提供 GUI 界面,用于在大量混合编程语言文件中进行搜索,使用的查询语言可以准确理解每种语言的词汇语法。
典型的查询:
将在 I 标识符附近查找 for 关键字,其名称必须以序列 index 开头,后跟 =< /strong> 运算符后跟一个值小于 10 的数字数字。由于 SCSE 理解语言结构,因此它不会受到空格或格式限制的困扰。它还将匹配 N 的十六进制值;它理解文字的不同格式,并根据数字的实际值而不是字符串提供查询。
给出这样的查询,GUI 将找到所有文件中的所有匹配项,并显示一组匹配项;单击命中即可看到源代码,并突出显示命中行。
要查找所有不为零的常量,您可以编写以下非常简单的查询:
您真正想要的是未在某种常量定义中定义的所有常量。所以你想从命中列表中删除任何常量定义,这
是通过使用“查询减法”运算符来完成的:
这会查找非零常量,并删除任何也与 const 声明匹配的常量。
您的其他梦想需要更复杂的引擎。本质上,您想要分析 C++ 代码(三法则)或使用一些新功能扩展 C++ 语言,然后使用标准 C++ 功能实现这些功能。您可以使用程序转换系统来完成此任务
可以操纵C++。
我们的 DMS Software Reengineering Toolkit 可以做到这一点。它有一个完整的 C++ 前端,可将 C++ 解析为内部编译器数据结构并构建完整的符号表(并且可以重新生成 C++ 源代码及其内部结构的所有详细信息)。使用该前端和 DMS 的内置模式匹配功能,您可以实施三规则检查。
对于语言扩展,您可以通过修改其语法来修改 DMS C++ 前端,以包含您认为理想的额外结构。然后,您可以编写程序转换来查找此类构造,并将它们转换为所需的代码。 (这个想法被 MS 名人 Charles Simyoni 称为意向编程,但这只是一个特例程序转换。)
DMS 已用于对实际 C++ 应用程序进行大规模自动化转换。从技术角度来看,它可以相当轻松地完成您的任务。
然而,要理解 C++ 的定义以及所有内容如何组合在一起,以及 DMS 如何支持转换,需要相当高的编译器风格复杂性。你建议做的不是一个下午或一周的工作。这需要在教育和努力方面进行大量投资。
但这比尝试仅从 YACC 开始要少得多。
Regarding finding constants, our SD Source Code Search Engine (SCSE) can do this off the shelf. SCSE provides GUI interface for search across large sets of mixed programming langauge files, using a query language that understands the lexical syntax of each language accurately.
A typical query:
will find for keywords near an Identifier whose name must start with the sequence index followed immediately by an = operator followed by a Number whose value is less than 10. Because SCSE understands the language structure, it isn't bothered by whitespace or formatting constraints. It will also match hexadecimal values for N; it understands the different format for literals and offers queries in terms of the actual value of the number, rather than as a string.
Given such a query, the GUI will find all matches across all your files, and show a set of hits; a click on a hit takes to you the source code with the hit line highlighted.
To find all constants that aren't zero, you write the following very simple query:
What you really want are all constants that aren't defined in some kind of constant definition. So you want to remove any constant-definitions from the hit list, which
is accomplished by using the "query subtract" operator:
This finds nonzero constants, and removes any that are also matched by the const declaration.
Your other dreams require a much more sophisticated engine. In essence, you want to analyze C++ code (your rule of three) or extend the C++ language with some new features, and then implement those features using standard C++ capabilities. You can accomplish this using a program transformation system
that can manipulate C++.
Our DMS Software Reengineering Tookit can do this. It has a full C++ front end that parses C++ to internal compiler data structures and builds complete symbol tables (and can regenerate C++ source code with all details from its internal structures). Using that front end and DMS's built in pattern matching capabilities, you could implement your rule-of-three check.
For language extensions, you can modify the DMS C++ front end by modifying its grammar to include the extra constructs you think ideal. Then, you can write program transformations that look for such constructs, and transform them into the desired code. (This idea was called intentional programming by Charles Simyoni of MS fame, but is just a special case of program transformation.)
DMS has been used to carry out massive automated transformations on real C++ applications. It could do your task fairly easily from a technical point of view.
However, understanding the definition of C++ and how everything fits together, and how DMS supports transformations, requires considerable compiler-style sophistication. What you suggest to do isn't an afternoon or a week's worth of work. It would take a significant investment in education and effort.
But a lot less than trying to do with starting with just YACC.