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