masters-thesis/op-finder/TestASTConsumer.hpp

63 lines
1.3 KiB
C++

//
// Created by erki on 24.02.21.
//
#ifndef C_ANALYZER_TESTASTCONSUMER_HPP
#define C_ANALYZER_TESTASTCONSUMER_HPP
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/AST/RecursiveASTVisitor.h>
class DebuggeringASTVisitor
: public clang::RecursiveASTVisitor<DebuggeringASTVisitor>
{
public:
explicit DebuggeringASTVisitor(clang::ASTContext* context)
: _context(context)
{ }
bool VisitBinaryOperator(clang::BinaryOperator* bo)
{
llvm::outs() << "OKAY FUCK YOU\n";
bo->dump();
return true;
}
private:
clang::ASTContext* _context;
};
class DebuggeringASTConsumer : public clang::ASTConsumer
{
public:
explicit DebuggeringASTConsumer(clang::ASTContext* context)
: _visitor(context)
{
}
void HandleTranslationUnit(clang::ASTContext& context) override
{
_visitor.TraverseAST(context);
}
private:
DebuggeringASTVisitor _visitor;
};
class DebuggeringASTAction : public clang::ASTFrontendAction
{
public:
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
clang::CompilerInstance &Compiler, llvm::StringRef InFile) override
{
return std::unique_ptr<clang::ASTConsumer>(
new DebuggeringASTConsumer(&Compiler.getASTContext()));
}
};
#endif //C_ANALYZER_TESTASTCONSUMER_HPP