我正在用 clang libtooling 编写一个重构工具。
我需要的是根据实时变量信息重写源代码。例如,对于函数中的每个基本块,转储其活出变量。
我知道如果我正在编写分析检查器会很容易。
void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
BugReporter &BR) const {
if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) {
L->dumpBlockLiveness(mgr.getSourceManager());
}
}
只需调用 mgr.getAnalysis(D) 即可获取此函数的 LiveVariables。然后,转储每个块。
但是,我正在编写一个独立的重构工具。如何构造 AnalysisManager 对象?
非常感谢。