66 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements the Mapper piece of the clang-doc tool. It implements10// a RecursiveASTVisitor to look at each declaration and populate the info11// into the internal representation. Each seen declaration is serialized to12// to bitcode and written out to the ExecutionContext as a KV pair where the13// 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_H18#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H19 20#include "Representation.h"21#include "clang/AST/RecursiveASTVisitor.h"22 23using namespace clang::comments;24using namespace clang::tooling;25 26namespace clang {27namespace doc {28 29class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>,30 public ASTConsumer {31public:32 explicit MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx)33 : CDCtx(CDCtx) {}34 35 void HandleTranslationUnit(ASTContext &Context) override;36 bool VisitNamespaceDecl(const NamespaceDecl *D);37 bool VisitRecordDecl(const RecordDecl *D);38 bool VisitEnumDecl(const EnumDecl *D);39 bool VisitCXXMethodDecl(const CXXMethodDecl *D);40 bool VisitFunctionDecl(const FunctionDecl *D);41 bool VisitTypedefDecl(const TypedefDecl *D);42 bool VisitTypeAliasDecl(const TypeAliasDecl *D);43 bool VisitConceptDecl(const ConceptDecl *D);44 bool VisitVarDecl(const VarDecl *D);45 46private:47 template <typename T> bool mapDecl(const T *D, bool IsDefinition);48 49 int getLine(const NamedDecl *D, const ASTContext &Context) const;50 51 Location getDeclLocation(const NamedDecl *D) const;52 53 llvm::SmallString<128> getFile(const NamedDecl *D, const ASTContext &Context,54 StringRef RootDir,55 bool &IsFileInRootDir) const;56 comments::FullComment *getComment(const NamedDecl *D,57 const ASTContext &Context) const;58 59 ClangDocContext CDCtx;60};61 62} // namespace doc63} // namespace clang64 65#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H66