| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB a KDAB Group company [email protected] |
| 3 |
SPDX-FileContributor: Sérgio Martins <[email protected]> |
| 4 |
|
| 5 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef CLAZY_MINI_AST_DUMPER |
| 9 |
#define CLAZY_MINI_AST_DUMPER |
| 10 |
|
| 11 |
#include <clang/AST/ASTConsumer.h> |
| 12 |
#include <clang/AST/RecursiveASTVisitor.h> |
| 13 |
#include <clang/Frontend/FrontendAction.h> |
| 14 |
#include <llvm/ADT/StringRef.h> |
| 15 |
|
| 16 |
#include <memory> |
| 17 |
#include <string> |
| 18 |
#include <vector> |
| 19 |
|
| 20 |
namespace clang |
| 21 |
{ |
| 22 |
class CompilerInstance; |
| 23 |
class ASTContext; |
| 24 |
class Decl; |
| 25 |
class Stmt; |
| 26 |
} |
| 27 |
|
| 28 |
class MiniAstDumperASTAction : public clang::PluginASTAction |
| 29 |
{ |
| 30 |
public: |
| 31 |
MiniAstDumperASTAction(); |
| 32 |
|
| 33 |
protected: |
| 34 |
bool ParseArgs(const clang::CompilerInstance &ci, const std::vector<std::string> &args_) override; |
| 35 |
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &ci, llvm::StringRef) override; |
| 36 |
}; |
| 37 |
|
| 38 |
class MiniASTDumperConsumer : public clang::ASTConsumer, public clang::RecursiveASTVisitor<MiniASTDumperConsumer> |
| 39 |
{ |
| 40 |
public: |
| 41 |
explicit MiniASTDumperConsumer(); |
| 42 |
~MiniASTDumperConsumer() override; |
| 43 |
|
| 44 |
bool VisitDecl(clang::Decl *decl); |
| 45 |
bool VisitStmt(clang::Stmt *stm); |
| 46 |
void HandleTranslationUnit(clang::ASTContext &ctx) override; |
| 47 |
|
| 48 |
private: |
| 49 |
MiniASTDumperConsumer(const MiniASTDumperConsumer &) = delete; |
| 50 |
}; |
| 51 |
|
| 52 |
#endif |