| 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 |
#include "MiniAstDumper.h" |
| 9 |
|
| 10 |
#include <clang/Basic/FileManager.h> |
| 11 |
#include <clang/Frontend/CompilerInstance.h> |
| 12 |
#include <clang/Frontend/FrontendPluginRegistry.h> |
| 13 |
|
| 14 |
using namespace clang; |
| 15 |
|
| 16 |
MiniAstDumperASTAction::MiniAstDumperASTAction() = default; |
| 17 |
|
| 18 |
bool MiniAstDumperASTAction::ParseArgs(const CompilerInstance &, const std::vector<std::string> &) |
| 19 |
{ |
| 20 |
return true; |
| 21 |
} |
| 22 |
|
| 23 |
std::unique_ptr<ASTConsumer> MiniAstDumperASTAction::CreateASTConsumer(CompilerInstance &, llvm::StringRef) |
| 24 |
{ |
| 25 |
return std::make_unique<MiniASTDumperConsumer>(); |
| 26 |
} |
| 27 |
|
| 28 |
MiniASTDumperConsumer::MiniASTDumperConsumer() = default; |
| 29 |
|
| 30 |
MiniASTDumperConsumer::~MiniASTDumperConsumer() = default; |
| 31 |
|
| 32 |
bool MiniASTDumperConsumer::VisitDecl(Decl *decl) |
| 33 |
{ |
| 34 |
if (auto *rec = dyn_cast<CXXRecordDecl>(decl)) { |
| 35 |
llvm::errs() << "Found record: " << rec->getQualifiedNameAsString() << "\n"; |
| 36 |
} |
| 37 |
|
| 38 |
return true; |
| 39 |
} |
| 40 |
|
| 41 |
bool MiniASTDumperConsumer::VisitStmt(Stmt *) |
| 42 |
{ |
| 43 |
return true; |
| 44 |
} |
| 45 |
|
| 46 |
void MiniASTDumperConsumer::HandleTranslationUnit(ASTContext &ctx) |
| 47 |
{ |
| 48 |
auto &sm = ctx.getSourceManager(); |
| 49 |
const auto fileEntry = sm.getFileEntryRefForID(sm.getMainFileID()); |
| 50 |
llvm::errs() << "Found TU: " << fileEntry->getName() << "\n"; |
| 51 |
TraverseDecl(ctx.getTranslationUnitDecl()); |
| 52 |
} |
| 53 |
|
| 54 |
static FrontendPluginRegistry::Add<MiniAstDumperASTAction> X2("clazyMiniAstDumper", "Clazy Mini AST Dumper plugin"); |