1e975a473SJulie Hockett //===-- Mapper.h - ClangDoc Mapper ------------------------------*- C++ -*-===// 2e975a473SJulie Hockett // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e975a473SJulie Hockett // 7e975a473SJulie Hockett //===----------------------------------------------------------------------===// 8e975a473SJulie Hockett // 9e975a473SJulie Hockett // This file implements the Mapper piece of the clang-doc tool. It implements 10e975a473SJulie Hockett // a RecursiveASTVisitor to look at each declaration and populate the info 11e975a473SJulie Hockett // into the internal representation. Each seen declaration is serialized to 12e975a473SJulie Hockett // to bitcode and written out to the ExecutionContext as a KV pair where the 13e975a473SJulie Hockett // key is the declaration's USR and the value is the serialized bitcode. 14e975a473SJulie Hockett // 15e975a473SJulie Hockett //===----------------------------------------------------------------------===// 16e975a473SJulie Hockett 17e975a473SJulie Hockett #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H 18e975a473SJulie Hockett #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H 19e975a473SJulie Hockett 20eb50a2e8SJulie Hockett #include "Representation.h" 21e975a473SJulie Hockett #include "clang/AST/RecursiveASTVisitor.h" 22e975a473SJulie Hockett #include "clang/Tooling/Execution.h" 23e975a473SJulie Hockett 24e975a473SJulie Hockett using namespace clang::comments; 25e975a473SJulie Hockett using namespace clang::tooling; 26e975a473SJulie Hockett 27e975a473SJulie Hockett namespace clang { 28e975a473SJulie Hockett namespace doc { 29e975a473SJulie Hockett 30e975a473SJulie Hockett class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>, 31e975a473SJulie Hockett public ASTConsumer { 32e975a473SJulie Hockett public: 33eb50a2e8SJulie Hockett explicit MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx) 34eb50a2e8SJulie Hockett : CDCtx(CDCtx) {} 35e975a473SJulie Hockett 36e975a473SJulie Hockett void HandleTranslationUnit(ASTContext &Context) override; 37e975a473SJulie Hockett bool VisitNamespaceDecl(const NamespaceDecl *D); 38e975a473SJulie Hockett bool VisitRecordDecl(const RecordDecl *D); 39e975a473SJulie Hockett bool VisitEnumDecl(const EnumDecl *D); 40e975a473SJulie Hockett bool VisitCXXMethodDecl(const CXXMethodDecl *D); 41e975a473SJulie Hockett bool VisitFunctionDecl(const FunctionDecl *D); 4221fb70c6SBrett Wilson bool VisitTypedefDecl(const TypedefDecl *D); 4321fb70c6SBrett Wilson bool VisitTypeAliasDecl(const TypeAliasDecl *D); 44e975a473SJulie Hockett 45e975a473SJulie Hockett private: 46*1b7631a6SPeterChou1 template <typename T> bool mapDecl(const T *D, bool IsDefinition); 47e975a473SJulie Hockett 48e975a473SJulie Hockett int getLine(const NamedDecl *D, const ASTContext &Context) const; 49665e9676SDiego Astiazaran llvm::SmallString<128> getFile(const NamedDecl *D, const ASTContext &Context, 50665e9676SDiego Astiazaran StringRef RootDir, 51665e9676SDiego Astiazaran bool &IsFileInRootDir) const; 52e975a473SJulie Hockett comments::FullComment *getComment(const NamedDecl *D, 53e975a473SJulie Hockett const ASTContext &Context) const; 54e975a473SJulie Hockett 55eb50a2e8SJulie Hockett ClangDocContext CDCtx; 56e975a473SJulie Hockett }; 57e975a473SJulie Hockett 58e975a473SJulie Hockett } // namespace doc 59e975a473SJulie Hockett } // namespace clang 60e975a473SJulie Hockett 61e975a473SJulie Hockett #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H 62