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