| 1 |
//===-- Mapper.h - ClangDoc Mapper ------------------------------*- C++ -*-===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// This file implements the Mapper piece of the clang-doc tool. It implements |
| 10 |
// a RecursiveASTVisitor to look at each declaration and populate the info |
| 11 |
// into the internal representation. Each seen declaration is serialized to |
| 12 |
// to bitcode and written out to the ExecutionContext as a KV pair where the |
| 13 |
// key is the declaration's USR and the value is the serialized bitcode. |
| 14 |
// |
| 15 |
//===----------------------------------------------------------------------===// |
| 16 |
|
| 17 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H |
| 18 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H |
| 19 |
|
| 20 |
#include "Representation.h" |
| 21 |
#include "clang/AST/RecursiveASTVisitor.h" |
| 22 |
#include "clang/Tooling/Execution.h" |
| 23 |
|
| 24 |
using namespace clang::comments; |
| 25 |
using namespace clang::tooling; |
| 26 |
|
| 27 |
namespace clang { |
| 28 |
namespace doc { |
| 29 |
|
| 30 |
class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>, |
| 31 |
public ASTConsumer { |
| 32 |
public: |
| 33 |
explicit MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx) |
| 34 |
: CDCtx(CDCtx) {} |
| 35 |
|
| 36 |
void HandleTranslationUnit(ASTContext &Context) override; |
| 37 |
bool VisitNamespaceDecl(const NamespaceDecl *D); |
| 38 |
bool VisitRecordDecl(const RecordDecl *D); |
| 39 |
bool VisitEnumDecl(const EnumDecl *D); |
| 40 |
bool VisitCXXMethodDecl(const CXXMethodDecl *D); |
| 41 |
bool VisitFunctionDecl(const FunctionDecl *D); |
| 42 |
bool VisitTypedefDecl(const TypedefDecl *D); |
| 43 |
bool VisitTypeAliasDecl(const TypeAliasDecl *D); |
| 44 |
|
| 45 |
private: |
| 46 |
template <typename T> bool mapDecl(const T *D); |
| 47 |
|
| 48 |
int getLine(const NamedDecl *D, const ASTContext &Context) const; |
| 49 |
llvm::SmallString<128> getFile(const NamedDecl *D, const ASTContext &Context, |
| 50 |
StringRef RootDir, |
| 51 |
bool &IsFileInRootDir) const; |
| 52 |
comments::FullComment *getComment(const NamedDecl *D, |
| 53 |
const ASTContext &Context) const; |
| 54 |
|
| 55 |
ClangDocContext CDCtx; |
| 56 |
}; |
| 57 |
|
| 58 |
} // namespace doc |
| 59 |
} // namespace clang |
| 60 |
|
| 61 |
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H |