Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 1 | //===-- ClangDoc.cpp - ClangDoc ---------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 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" |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 17 | #include "Representation.h" |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 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: |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 31 | MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {} |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 32 | clang::FrontendAction *create() override; |
| 33 | |
| 34 | private: |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 35 | ClangDocContext CDCtx; |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | clang::FrontendAction *MapperActionFactory::create() { |
| 39 | class ClangDocAction : public clang::ASTFrontendAction { |
| 40 | public: |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 41 | ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {} |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 42 | |
| 43 | std::unique_ptr<clang::ASTConsumer> |
| 44 | CreateASTConsumer(clang::CompilerInstance &Compiler, |
| 45 | llvm::StringRef InFile) override { |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 46 | return llvm::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx); |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | private: |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 50 | ClangDocContext CDCtx; |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 51 | }; |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 52 | return new ClangDocAction(CDCtx); |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | std::unique_ptr<tooling::FrontendActionFactory> |
Julie Hockett | eb50a2e | 2018-07-20 18:49:55 +0000 | [diff] [blame] | 56 | newMapperActionFactory(ClangDocContext CDCtx) { |
| 57 | return llvm::make_unique<MapperActionFactory>(CDCtx); |
Julie Hockett | e975a47 | 2018-03-22 23:34:46 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace doc |
| 61 | } // namespace clang |