File size: 1,562 Bytes
b27bfb3 | 1 2 3 4 5 | {"type": "session", "harness": "deepseek-harness", "id": "clang001", "name": "Clang LibTooling basics"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "How do I use Clang LibTooling for code analysis?"}}
{"type": "message", "message": {"role": "assistant", "content": "```cpp\n#include \"clang/Tooling/CommonOptionsParser.h\"\n#include \"clang/Tooling/Tooling.h\"\n#include \"clang/ASTMatchers/ASTMatchers.h\"\n#include \"clang/ASTMatchers/ASTMatchFinder.h\"\n\nclass FunctionPrinter : public MatchFinder::MatchCallback {\n void run(const MatchFinder::MatchResult &Result) override {\n if (auto *FD = Result.Nodes.getNodeAs<clang::FunctionDecl>(\"func\"))\n llvm::outs() << \"Found: \" << FD->getNameAsString() << \"\\n\";\n }\n};\n\nint main(int argc, const char **argv) {\n auto EP = CommonOptionsParser::create(argc, argv, MyCategory);\n ClangTool Tool(EP.get().getCompilations(), EP.get().getSourcePathList());\n FunctionPrinter Printer;\n Finder.addMatcher(functionDecl().bind(\"func\"), &Printer);\n return Tool.run(newFrontendActionFactory(&Finder).get());\n}\n```"}}
|