blob: ec32f012411275ea1876f40a6f814fb8353cd8e8 [file] [log] [blame]
Julie Hockette975a472018-03-22 23:34:46 +00001//===-- ClangDoc.cpp - ClangDoc ---------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Julie Hockette975a472018-03-22 23:34:46 +00006//
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"
Julie Hocketteb50a2e2018-07-20 18:49:55 +000017#include "Representation.h"
Julie Hockette975a472018-03-22 23:34:46 +000018#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:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000031 MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
Julie Hockette975a472018-03-22 23:34:46 +000032 clang::FrontendAction *create() override;
33
34private:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000035 ClangDocContext CDCtx;
Julie Hockette975a472018-03-22 23:34:46 +000036};
37
38clang::FrontendAction *MapperActionFactory::create() {
39 class ClangDocAction : public clang::ASTFrontendAction {
40 public:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000041 ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
Julie Hockette975a472018-03-22 23:34:46 +000042
43 std::unique_ptr<clang::ASTConsumer>
44 CreateASTConsumer(clang::CompilerInstance &Compiler,
45 llvm::StringRef InFile) override {
Julie Hocketteb50a2e2018-07-20 18:49:55 +000046 return llvm::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx);
Julie Hockette975a472018-03-22 23:34:46 +000047 }
48
49 private:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000050 ClangDocContext CDCtx;
Julie Hockette975a472018-03-22 23:34:46 +000051 };
Julie Hocketteb50a2e2018-07-20 18:49:55 +000052 return new ClangDocAction(CDCtx);
Julie Hockette975a472018-03-22 23:34:46 +000053}
54
55std::unique_ptr<tooling::FrontendActionFactory>
Julie Hocketteb50a2e2018-07-20 18:49:55 +000056newMapperActionFactory(ClangDocContext CDCtx) {
57 return llvm::make_unique<MapperActionFactory>(CDCtx);
Julie Hockette975a472018-03-22 23:34:46 +000058}
59
60} // namespace doc
61} // namespace clang