Mapper.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
  17. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
  18. #include "Representation.h"
  19. #include "clang/AST/RecursiveASTVisitor.h"
  20. #include "clang/Tooling/Execution.h"
  21. using namespace clang::comments;
  22. using namespace clang::tooling;
  23. namespace clang {
  24. namespace doc {
  25. class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>,
  26. public ASTConsumer {
  27. public:
  28. explicit MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx)
  29. : CDCtx(CDCtx) {}
  30. void HandleTranslationUnit(ASTContext &Context) override;
  31. bool VisitNamespaceDecl(const NamespaceDecl *D);
  32. bool VisitRecordDecl(const RecordDecl *D);
  33. bool VisitEnumDecl(const EnumDecl *D);
  34. bool VisitCXXMethodDecl(const CXXMethodDecl *D);
  35. bool VisitFunctionDecl(const FunctionDecl *D);
  36. private:
  37. template <typename T> bool mapDecl(const T *D);
  38. int getLine(const NamedDecl *D, const ASTContext &Context) const;
  39. llvm::SmallString<128> getFile(const NamedDecl *D, const ASTContext &Context,
  40. StringRef RootDir,
  41. bool &IsFileInRootDir) const;
  42. comments::FullComment *getComment(const NamedDecl *D,
  43. const ASTContext &Context) const;
  44. ClangDocContext CDCtx;
  45. };
  46. } // namespace doc
  47. } // namespace clang
  48. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H