llvm-project
61 строка · 1.9 Кб
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
26namespace clang {
27namespace doc {
28
29class MapperActionFactory : public tooling::FrontendActionFactory {
30public:
31MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
32std::unique_ptr<FrontendAction> create() override;
33
34private:
35ClangDocContext CDCtx;
36};
37
38std::unique_ptr<FrontendAction> MapperActionFactory::create() {
39class ClangDocAction : public clang::ASTFrontendAction {
40public:
41ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
42
43std::unique_ptr<clang::ASTConsumer>
44CreateASTConsumer(clang::CompilerInstance &Compiler,
45llvm::StringRef InFile) override {
46return std::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx);
47}
48
49private:
50ClangDocContext CDCtx;
51};
52return std::make_unique<ClangDocAction>(CDCtx);
53}
54
55std::unique_ptr<tooling::FrontendActionFactory>
56newMapperActionFactory(ClangDocContext CDCtx) {
57return std::make_unique<MapperActionFactory>(CDCtx);
58}
59
60} // namespace doc
61} // namespace clang
62