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" |
| 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: |
| 31 | MapperActionFactory(tooling::ExecutionContext *ECtx) : ECtx(ECtx) {} |
| 32 | clang::FrontendAction *create() override; |
| 33 | |
| 34 | private: |
| 35 | tooling::ExecutionContext *ECtx; |
| 36 | }; |
| 37 | |
| 38 | clang::FrontendAction *MapperActionFactory::create() { |
| 39 | class ClangDocAction : public clang::ASTFrontendAction { |
| 40 | public: |
| 41 | ClangDocAction(ExecutionContext *ECtx) : ECtx(ECtx) {} |
| 42 | |
| 43 | std::unique_ptr<clang::ASTConsumer> |
| 44 | CreateASTConsumer(clang::CompilerInstance &Compiler, |
| 45 | llvm::StringRef InFile) override { |
| 46 | return llvm::make_unique<MapASTVisitor>(&Compiler.getASTContext(), ECtx); |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | ExecutionContext *ECtx; |
| 51 | }; |
| 52 | return new ClangDocAction(ECtx); |
| 53 | } |
| 54 | |
| 55 | std::unique_ptr<tooling::FrontendActionFactory> |
| 56 | newMapperActionFactory(tooling::ExecutionContext *ECtx) { |
| 57 | return llvm::make_unique<MapperActionFactory>(ECtx); |
| 58 | } |
| 59 | |
| 60 | } // namespace doc |
| 61 | } // namespace clang |