File indexing completed on 2024-04-14 05:32:07
0001 /* 0002 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB a KDAB Group company info@kdab.com 0003 SPDX-FileContributor: Sérgio Martins <sergio.martins@kdab.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "MiniAstDumper.h" 0009 0010 #include <clang/Basic/FileManager.h> 0011 #include <clang/Frontend/CompilerInstance.h> 0012 #include <clang/Frontend/FrontendPluginRegistry.h> 0013 0014 using namespace clang; 0015 0016 MiniAstDumperASTAction::MiniAstDumperASTAction() 0017 { 0018 } 0019 0020 bool MiniAstDumperASTAction::ParseArgs(const CompilerInstance &, const std::vector<std::string> &) 0021 { 0022 return true; 0023 } 0024 0025 std::unique_ptr<ASTConsumer> MiniAstDumperASTAction::CreateASTConsumer(CompilerInstance &, llvm::StringRef) 0026 { 0027 return std::unique_ptr<MiniASTDumperConsumer>(new MiniASTDumperConsumer()); 0028 } 0029 0030 MiniASTDumperConsumer::MiniASTDumperConsumer() 0031 { 0032 } 0033 0034 MiniASTDumperConsumer::~MiniASTDumperConsumer() 0035 { 0036 } 0037 0038 bool MiniASTDumperConsumer::VisitDecl(Decl *decl) 0039 { 0040 if (auto *rec = dyn_cast<CXXRecordDecl>(decl)) { 0041 llvm::errs() << "Found record: " << rec->getQualifiedNameAsString() << "\n"; 0042 } 0043 0044 return true; 0045 } 0046 0047 bool MiniASTDumperConsumer::VisitStmt(Stmt *) 0048 { 0049 return true; 0050 } 0051 0052 void MiniASTDumperConsumer::HandleTranslationUnit(ASTContext &ctx) 0053 { 0054 auto &sm = ctx.getSourceManager(); 0055 const FileEntry *fileEntry = sm.getFileEntryForID(sm.getMainFileID()); 0056 llvm::errs() << "Found TU: " << fileEntry->getName() << "\n"; 0057 TraverseDecl(ctx.getTranslationUnitDecl()); 0058 } 0059 0060 static FrontendPluginRegistry::Add<MiniAstDumperASTAction> X2("clazyMiniAstDumper", "Clazy Mini AST Dumper plugin");