blob: a11c5840041cdfee1e921fc910eea173b844a420 [file] [log] [blame]
Julie Hockette975a472018-03-22 23:34:46 +00001//===-- ClangDoc.cpp - ClangDoc ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the main entry point for the clang-doc tool. It runs
11// the clang-doc mapper on a given set of source code files using a
12// FrontendActionFactory.
13//
14//===----------------------------------------------------------------------===//
15
16#include "ClangDoc.h"
17#include "Mapper.h"
Julie Hocketteb50a2e2018-07-20 18:49:55 +000018#include "Representation.h"
Julie Hockette975a472018-03-22 23:34:46 +000019#include "clang/AST/AST.h"
20#include "clang/AST/ASTConsumer.h"
21#include "clang/AST/ASTContext.h"
22#include "clang/AST/RecursiveASTVisitor.h"
23#include "clang/Frontend/ASTConsumers.h"
24#include "clang/Frontend/CompilerInstance.h"
25#include "clang/Frontend/FrontendActions.h"
26
27namespace clang {
28namespace doc {
29
30class MapperActionFactory : public tooling::FrontendActionFactory {
31public:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000032 MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
Julie Hockette975a472018-03-22 23:34:46 +000033 clang::FrontendAction *create() override;
34
35private:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000036 ClangDocContext CDCtx;
Julie Hockette975a472018-03-22 23:34:46 +000037};
38
39clang::FrontendAction *MapperActionFactory::create() {
40 class ClangDocAction : public clang::ASTFrontendAction {
41 public:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000042 ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
Julie Hockette975a472018-03-22 23:34:46 +000043
44 std::unique_ptr<clang::ASTConsumer>
45 CreateASTConsumer(clang::CompilerInstance &Compiler,
46 llvm::StringRef InFile) override {
Julie Hocketteb50a2e2018-07-20 18:49:55 +000047 return llvm::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx);
Julie Hockette975a472018-03-22 23:34:46 +000048 }
49
50 private:
Julie Hocketteb50a2e2018-07-20 18:49:55 +000051 ClangDocContext CDCtx;
Julie Hockette975a472018-03-22 23:34:46 +000052 };
Julie Hocketteb50a2e2018-07-20 18:49:55 +000053 return new ClangDocAction(CDCtx);
Julie Hockette975a472018-03-22 23:34:46 +000054}
55
56std::unique_ptr<tooling::FrontendActionFactory>
Julie Hocketteb50a2e2018-07-20 18:49:55 +000057newMapperActionFactory(ClangDocContext CDCtx) {
58 return llvm::make_unique<MapperActionFactory>(CDCtx);
Julie Hockette975a472018-03-22 23:34:46 +000059}
60
61} // namespace doc
62} // namespace clang