tinycodinglm / lang /clang001.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
1.56 kB
deepseek-harness trace
System 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 c...

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.

User

How do I use Clang LibTooling for code analysis?

Assistant
cpp
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

class FunctionPrinter : public MatchFinder::MatchCallback {
    void run(const MatchFinder::MatchResult &Result) override {
        if (auto *FD = Result.Nodes.getNodeAs<clang::FunctionDecl>("func"))
            llvm::outs() << "Found: " << FD->getNameAsString() << "\n";
    }
};

int main(int argc, const char **argv) {
    auto EP = CommonOptionsParser::create(argc, argv, MyCategory);
    ClangTool Tool(EP.get().getCompilations(), EP.get().getSourcePathList());
    FunctionPrinter Printer;
    Finder.addMatcher(functionDecl().bind("func"), &Printer);
    return Tool.run(newFrontendActionFactory(&Finder).get());
}