ClangDoc.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //===-- ClangDoc.cpp - ClangDoc ---------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the main entry point for the clang-doc tool. It runs
  10. // the clang-doc mapper on a given set of source code files using a
  11. // FrontendActionFactory.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "ClangDoc.h"
  15. #include "Mapper.h"
  16. #include "Representation.h"
  17. #include "clang/AST/AST.h"
  18. #include "clang/AST/ASTConsumer.h"
  19. #include "clang/AST/ASTContext.h"
  20. #include "clang/AST/RecursiveASTVisitor.h"
  21. #include "clang/Frontend/ASTConsumers.h"
  22. #include "clang/Frontend/CompilerInstance.h"
  23. #include "clang/Frontend/FrontendActions.h"
  24. namespace clang {
  25. namespace doc {
  26. class MapperActionFactory : public tooling::FrontendActionFactory {
  27. public:
  28. MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
  29. std::unique_ptr<FrontendAction> create() override;
  30. private:
  31. ClangDocContext CDCtx;
  32. };
  33. std::unique_ptr<FrontendAction> MapperActionFactory::create() {
  34. class ClangDocAction : public clang::ASTFrontendAction {
  35. public:
  36. ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
  37. std::unique_ptr<clang::ASTConsumer>
  38. CreateASTConsumer(clang::CompilerInstance &Compiler,
  39. llvm::StringRef InFile) override {
  40. return std::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx);
  41. }
  42. private:
  43. ClangDocContext CDCtx;
  44. };
  45. return std::make_unique<ClangDocAction>(CDCtx);
  46. }
  47. std::unique_ptr<tooling::FrontendActionFactory>
  48. newMapperActionFactory(ClangDocContext CDCtx) {
  49. return std::make_unique<MapperActionFactory>(CDCtx);
  50. }
  51. } // namespace doc
  52. } // namespace clang