clang-tools  14.0.0git
ClangDoc.cpp
Go to the documentation of this file.
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 
15 #include "ClangDoc.h"
16 #include "Mapper.h"
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"
25 
26 namespace clang {
27 namespace doc {
28 
29 class MapperActionFactory : public tooling::FrontendActionFactory {
30 public:
31  MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
32  std::unique_ptr<FrontendAction> create() override;
33 
34 private:
35  ClangDocContext CDCtx;
36 };
37 
38 std::unique_ptr<FrontendAction> MapperActionFactory::create() {
39  class ClangDocAction : public clang::ASTFrontendAction {
40  public:
41  ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
42 
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);
47  }
48 
49  private:
50  ClangDocContext CDCtx;
51  };
52  return std::make_unique<ClangDocAction>(CDCtx);
53 }
54 
55 std::unique_ptr<tooling::FrontendActionFactory>
57  return std::make_unique<MapperActionFactory>(CDCtx);
58 }
59 
60 } // namespace doc
61 } // namespace clang
clang::doc::MapperActionFactory::MapperActionFactory
MapperActionFactory(ClangDocContext CDCtx)
Definition: ClangDoc.cpp:31
clang::doc::MapperActionFactory::create
std::unique_ptr< FrontendAction > create() override
Definition: ClangDoc.cpp:38
Representation.h
ClangDoc.h
clang::doc::ClangDocContext
Definition: Representation.h:426
clang::doc::newMapperActionFactory
std::unique_ptr< tooling::FrontendActionFactory > newMapperActionFactory(ClangDocContext CDCtx)
Definition: ClangDoc.cpp:56
clang::doc::MapperActionFactory
Definition: ClangDoc.cpp:29
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
Mapper.h