C ++头文件解析 [英] C++ header file parsing

查看:344
本文介绍了C ++头文件解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解析一个头文件。
我的目标是从头文件中搜索特定的结构,并提取结构变量的值和偏移量。

I need to parse a header file. My goal is to search the specific structure from the header file and extract the values and offsets of the structure variables.

任何一个请建议最好的方法

Can any one please suggest the best way for parsing the header file by omitting the comments and how to parse macros from header too?

推荐答案

解析C ++比较困难,可以通过解析头文件来解析头文件。您可能想要使用现有的解析器。我知道4个很有用:

Parsing C++ is tough. You'll likely want to use an existing parser. I know of 4 that are probably useful:


  • Edison Design Group前端

  • Clang的C ++解析器

  • DMS软件重新构建工具包及其C ++ 14前端

  • GCC(通过Melt)

  • Edison Design Group front end
  • Clang's C++ parser
  • DMS Software Reengineering Toolkit and its C++14 front end
  • GCC (via Melt)

这些大多数不会解析宏;他们希望使用预处理器 扩展它们。所以宏和PP条件从解析树中消失。
DMS可以进行有限的预处理,并收集/保存在结构良好的地方以及它们通常发生的各种地方找到的预处理器指令和宏。

Most of these won't "parse" macros; they want to expand them using a preprocessor. So macros and PP conditionals disappear from the parse tree. DMS can do "limited" preprocessing, and collect/keep preprocessor directives and macros found in well structured places and a wide variety of places they commonly occur.

解析头文件真的很难;它们往往被来自许多先前版本的软件的条件和垃圾加载,并且来自特定供应商的习语。 (MS的头部有一些奇怪的东西)。除非你在谈论解析 头文件,确保你选择的工具可以处理你正在处理的C ++方言。

Parsing header files is really tough; they tend to be loaded with conditionals and junk from many previous versions of the software, and idioms from the specific vendor. (MS has some stunningly weird stuff in their headers). Unless you are talking about parsing your header files, make sure you check the tool you choose can handle the dialect of C++ that you are actually handling.

这篇关于C ++头文件解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆