本段代码给出了一个如何在clang中实现FrontendAction返回一个自己需要的返回值的例子
class MyFrontendAction : public ASTFrontendAction { public: MyFrontendAction(ReturnClass* return) { result = return; } void EndSourceFileAction() override; std::unique_ptr CreateASTConsumer(CompilerInstance& CI, StringRef file) override; private: ReturnClass* result ; }; std::unique_ptr MyFrontendAction::CreateASTConsumer(CompilerInstance& CI, StringRef file) { cur_callgraph = nullptr; return std::make_unique(file); } // 在处理单个输入结束时回调 void MyFrontendAction::EndSourceFileAction() { //getCompilerInstance().getASTConsumer()... //result = ...; } class MyFrontendActionFactory :public FrontendActionFactory { public: MyFrontendActionFactory(FrontendAction* frontAct) { act = frontAct; } std::unique_ptr create() override { return std::unique_ptr (act); } private: FrontendAction* act; }; int run(ClangTool tool){ ReturnClass* return; std::unique_ptr myActPtr(new MyFrontendAction(return)); std::unique_ptr myActFactoryPtr(new CFGFrontendActionFactory(myActPtr.get())); int re = tool.run(myActFactoryPtr.get()); myActFactoryPtr.release(); myActPtr.release(); return re; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)