用于预处理器 #if 语句的工具/解析器?
我正在处理许多 C 源代码文件,其中包含许多预处理器 #if
、#elseif
和 #else
语句。
该语句经常检查#define
,例如
#if(Switch_TestMode == Switch_TestModeON)
/* code 1 */
#else
/*code 2 */
#endif
,该预处理器语句通常位于c-if 语句内,这使得源代码对于人类来说几乎不可读。
用于此预处理器#if
语句的#define
是在额外文件中定义的。
我现在的想法是拥有一个工具来检查此#define
d 开关设置,然后仅复制使用当前#define/switch 设置应用的源代码行。
对于上面的示例,我想获取一个新的 .c 文件,其中仅包含
/*code 2 */
假设 Switch_TestMode
的 #define
不等于 Switch_TestModeON
。
是否有可用的工具(免费软件||低成本)可以完成这项工作? 或者我是否必须为此编写自己的预处理器解析器?
(我不可能使用完成这项工作的特殊参数来运行编译器,因为我们公司正在创建 C 源代码,另一家公司正在编译。)
感谢您的任何提示!
问候
托马斯
I am working on many C-sourcecode files which contain many preprocessor #if
, #elseif
and #else
statements.
This statements often check for a #define
, e.g.
#if(Switch_TestMode == Switch_TestModeON)
/* code 1 */
#else
/*code 2 */
#endif
Often this preprocessor statements are located within c-if statements which makes the sourcecode nearly unreadable for human beeings.
The #define
s used for this preprocessor #if
statements are defined within an extra file.
My idea now is to have a tool which checks this #define
d switch settings and then only copies the lines of sourcecode which apply using the current #defines/switch settings.
For the above example I would like to get a new .c file which contains only
/*code 2 */
assumed the #define
of Switch_TestMode
is not equal to Switch_TestModeON
.
Are there tools (freeware || low-cost) available which do this job?
Or do I have to write my own preprocessor parser for this?
(It is impossible for me to run the compiler using a special parameter which does this job, because our company is creating the C-sourcecode, another company is compiling.)
Thanks for any hint!
Regards
Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
unifdef 可从 http://dotat.at/prog/unifdef/ 获取。
unifdef is available from http://dotat.at/prog/unifdef/.
尝试 Sunifdef
编辑:现在已成为 科恩
Try Sunifdef
Edit: Which has now become Coan
您可以使用命令行选项 -E 运行 GNU 编译器来进行预处理。
http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html
You can run the GNU compiler using command line option -E to do the preprocessing.
http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html
您可以使用 unifdef。
You can use unifdef.