2018-03-23 07:34:46 +08:00
|
|
|
//===-- ClangDoc.cpp - ClangDoc ---------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-03-23 07:34:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the main entry point for the clang-doc tool. It runs
|
|
|
|
// the clang-doc mapper on a given set of source code files using a
|
|
|
|
// FrontendActionFactory.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangDoc.h"
|
|
|
|
#include "Mapper.h"
|
2018-07-21 02:49:55 +08:00
|
|
|
#include "Representation.h"
|
2018-03-23 07:34:46 +08:00
|
|
|
#include "clang/AST/AST.h"
|
|
|
|
#include "clang/AST/ASTConsumer.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/RecursiveASTVisitor.h"
|
|
|
|
#include "clang/Frontend/ASTConsumers.h"
|
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Frontend/FrontendActions.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace doc {
|
|
|
|
|
|
|
|
class MapperActionFactory : public tooling::FrontendActionFactory {
|
|
|
|
public:
|
2018-07-21 02:49:55 +08:00
|
|
|
MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
|
2019-08-30 00:38:36 +08:00
|
|
|
std::unique_ptr<FrontendAction> create() override;
|
2018-03-23 07:34:46 +08:00
|
|
|
|
|
|
|
private:
|
2018-07-21 02:49:55 +08:00
|
|
|
ClangDocContext CDCtx;
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
|
|
|
|
2019-08-30 00:38:36 +08:00
|
|
|
std::unique_ptr<FrontendAction> MapperActionFactory::create() {
|
2018-03-23 07:34:46 +08:00
|
|
|
class ClangDocAction : public clang::ASTFrontendAction {
|
|
|
|
public:
|
2018-07-21 02:49:55 +08:00
|
|
|
ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
|
2018-03-23 07:34:46 +08:00
|
|
|
|
|
|
|
std::unique_ptr<clang::ASTConsumer>
|
|
|
|
CreateASTConsumer(clang::CompilerInstance &Compiler,
|
|
|
|
llvm::StringRef InFile) override {
|
2019-08-15 07:52:23 +08:00
|
|
|
return std::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx);
|
2018-03-23 07:34:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-07-21 02:49:55 +08:00
|
|
|
ClangDocContext CDCtx;
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
2019-08-30 00:38:36 +08:00
|
|
|
return std::make_unique<ClangDocAction>(CDCtx);
|
2018-03-23 07:34:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<tooling::FrontendActionFactory>
|
2018-07-21 02:49:55 +08:00
|
|
|
newMapperActionFactory(ClangDocContext CDCtx) {
|
2019-08-15 07:52:23 +08:00
|
|
|
return std::make_unique<MapperActionFactory>(CDCtx);
|
2018-03-23 07:34:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace doc
|
|
|
|
} // namespace clang
|