Mapper.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. bool VisitTypedefDecl(const TypedefDecl *D);
  37. bool VisitTypeAliasDecl(const TypeAliasDecl *D);
  38. private:
  39. template <typename T> bool mapDecl(const T *D);
  40. int getLine(const NamedDecl *D, const ASTContext &Context) const;
  41. llvm::SmallString<128> getFile(const NamedDecl *D, const ASTContext &Context,
  42. StringRef RootDir,
  43. bool &IsFileInRootDir) const;
  44. comments::FullComment *getComment(const NamedDecl *D,
  45. const ASTContext &Context) const;
  46. ClangDocContext CDCtx;
  47. };
  48. } // namespace doc
  49. } // namespace clang
  50. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H