From eec22486f3680d43d5e58d2c75428ee418c6ae98 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Wed, 25 Sep 2024 15:28:04 +0900 Subject: Use C++ namespace --- goatc.cc | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'goatc.cc') diff --git a/goatc.cc b/goatc.cc index 354d377..607d056 100644 --- a/goatc.cc +++ b/goatc.cc @@ -19,35 +19,43 @@ #include "goatc.hh" #include -#include #include #include #include bool -GoatCConsumer::HandleTopLevelDecl (clang::DeclGroupRef dg) +goatc::Visitor::VisitDecl (clang::Decl* decl) { - if (this->noop) - return true; - - for (auto const& d : dg) - if (auto const& nd = llvm::dyn_cast (d)) - llvm::errs() << "top-level-decl: \"" << nd->getNameAsString() << "\"\n"; + if (auto* named_decl = llvm::dyn_cast (decl)) + { + clang::FullSourceLoc loc = this->ctx->getFullLoc (decl->getBeginLoc ()); + if (loc.isValid ()) + llvm::outs () + << "Found " << named_decl->getQualifiedNameAsString () + << " at " << loc.getSpellingLineNumber () + << ':' << loc.getSpellingColumnNumber () << '\n'; + } return true; } +void +goatc::Consumer::HandleTranslationUnit (clang::ASTContext& ctx) +{ + this->visitor.TraverseDecl (ctx.getTranslationUnitDecl ()); +} + clang::PluginASTAction::ActionType -GoatCAction::getActionType () +goatc::Action::getActionType () { return AddBeforeMainAction; } std::unique_ptr -GoatCAction::CreateASTConsumer (clang::CompilerInstance& ci, - llvm::StringRef in_file) +goatc::Action::CreateASTConsumer (clang::CompilerInstance& ci, + llvm::StringRef in_file) { - llvm::errs () << in_file << '\n'; - return std::make_unique (ci, in_file != this->source_file); + return std::make_unique (&ci.getASTContext (), + in_file != this->source_file); } void @@ -59,14 +67,14 @@ printHelp (llvm::raw_ostream& ros) } bool -GoatCAction::ParseArgs (const clang::CompilerInstance& ci, - const std::vector &args) +goatc::Action::ParseArgs (const clang::CompilerInstance& ci, + const std::vector &args) { auto& d = ci.getDiagnostics (); for (unsigned i = 0, e = args.size(); i < e; ++i) if (args[i] == "-h" || args[i] == "--help") { - printHelp (llvm::errs ()); + printHelp (llvm::outs ()); // FIXME: exit with status 0 return false; } -- cgit 1.4.1