ExtractAPIConsumer.cpp 835 B

1234567891011121314151617181920212223242526272829303132
  1. #include "clang/AST/ASTConsumer.h"
  2. #include "clang/AST/RecursiveASTVisitor.h"
  3. #include "clang/Frontend/ASTConsumers.h"
  4. #include "clang/Frontend/CompilerInstance.h"
  5. #include "clang/Frontend/FrontendActions.h"
  6. using namespace clang;
  7. namespace {
  8. class ExtractAPIVisitor : public RecursiveASTVisitor<ExtractAPIVisitor> {
  9. public:
  10. bool VisitNamedDecl(NamedDecl *Decl) {
  11. llvm::outs() << Decl->getName() << "\n";
  12. return true;
  13. }
  14. };
  15. class ExtractAPIConsumer : public ASTConsumer {
  16. public:
  17. void HandleTranslationUnit(ASTContext &Context) override {
  18. Visitor.TraverseDecl(Context.getTranslationUnitDecl());
  19. }
  20. private:
  21. ExtractAPIVisitor Visitor;
  22. };
  23. } // namespace
  24. std::unique_ptr<ASTConsumer>
  25. ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
  26. return std::make_unique<ExtractAPIConsumer>();
  27. }