使用clang来分析C ++代码 [英] Using clang to analyze C++ code

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

问题描述

我们想对用户的C ++代码进行一些相当简单的分析,然后使用这些信息来测试他们的代码(基本上用一些测试代码重新生成他们的代码),以便用户可以对他们的代码进行动态分析, stats对某些数值类型的值范围的事情。

We want to do some fairly simple analysis of user's C++ code and then use that information to instrument their code (basically regen their code with a bit of instrumentation code) so that the user can run a dynamic analysis of their code and get stats on things like ranges of values of certain numeric types.

clang应该能够处理足够的C ++来处理我们的用户会抛出的那种代码 - 并且因为clang的C ++覆盖在我们完成之后不断改进会更好。

clang should be able to handle enough C++ now to handle the kind of code our users would be throwing at it - and since clang's C++ coverage is continuously improving by the time we're done it'll be even better.

那么如何使用铛这样作为一个独立的解析器?我们认为我们可以生成一个AST,然后寻找我们有兴趣跟踪的类的对象。

So how does one go about using clang like this as a standalone parser? We're thinking we could just generate an AST and then walk it looking for objects of the classes we're interested in tracking. Would be interested in hearing from others who are using clang without LLVM.

推荐答案

clang 设计为模块化。从其页面引用:

clang is designed to be modular. Quoting from its page:


clang的主要设计概念是
其使用基于库的
架构。在这个设计中,前端的各种
部分可以干净地
分成单独的库,然后
可以混合起来用于不同的
需要和使用。

A major design concept for clang is its use of a library-based architecture. In this design, various parts of the front-end can be cleanly divided into separate libraries which can then be mixed up for different needs and uses.

查看像 libast 的clang库以满足您的需求。阅读更多这里

Look at clang libraries like libast for your needs. Read more here.

这篇关于使用clang来分析C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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