1 //===-- ClangDoc.cpp - ClangDoc ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
17 #include "Representation.h"
18 #include "clang/AST/AST.h"
19 #include "clang/AST/ASTConsumer.h"
20 #include "clang/AST/ASTContext.h"
21 #include "clang/AST/RecursiveASTVisitor.h"
22 #include "clang/Frontend/ASTConsumers.h"
23 #include "clang/Frontend/CompilerInstance.h"
24 #include "clang/Frontend/FrontendActions.h"
29 class MapperActionFactory
: public tooling::FrontendActionFactory
{
31 MapperActionFactory(ClangDocContext CDCtx
) : CDCtx(CDCtx
) {}
32 std::unique_ptr
<FrontendAction
> create() override
;
35 ClangDocContext CDCtx
;
38 std::unique_ptr
<FrontendAction
> MapperActionFactory::create() {
39 class ClangDocAction
: public clang::ASTFrontendAction
{
41 ClangDocAction(ClangDocContext CDCtx
) : CDCtx(CDCtx
) {}
43 std::unique_ptr
<clang::ASTConsumer
>
44 CreateASTConsumer(clang::CompilerInstance
&Compiler
,
45 llvm::StringRef InFile
) override
{
46 return std::make_unique
<MapASTVisitor
>(&Compiler
.getASTContext(), CDCtx
);
50 ClangDocContext CDCtx
;
52 return std::make_unique
<ClangDocAction
>(CDCtx
);
55 std::unique_ptr
<tooling::FrontendActionFactory
>
56 newMapperActionFactory(ClangDocContext CDCtx
) {
57 return std::make_unique
<MapperActionFactory
>(CDCtx
);